Database connectionstring windows authentication but passing user and password - authentication

I need some help.
I'm trying to connect to my database.
This is my connectionstring :
<add name="DefaultConnection" connectionString="Data Source=KBV-SQL12-TEST\KBSQLSPTEST; Initial Catalog=KBSPT_aspnetmembership; User Id=KBOVDM01\KBSPT_EXTRANET; Password=SPExtr#n3t" providerName="System.Data.SqlClient" />
The user is an Active Directory user.
When I go to my SQLServer and log on as KBSPT_EXTRANET, I can op the SQL Management Studio and connect to the database.
But in my application when I use the connectionstring mentionned above, I keep getting the message "Underlying provider failed on open".
What am I doing wrong?

You are trying to use a Windows account when the connection string is expecting a SQL Server user account.

Related

ArgumentException: Keyword not supported: 'server'

I have an Asp.net MVC5 application and have published it to Microsoft Azure. I first migrated my .mdf files toSql Azure Databases. The database connection string provided in the Azure Portal is not working.
[ArgumentException: Keyword not supported: 'server'.]
My connection string is as follows web.config
connectionString="
Server=tcp:dbprojectserver.database.windows.net,1433;
Initial Catalog=db_project;
Persist Security Info=False;
User ID=username#servername;
Password=kenth&&123;
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=30;
"
I believe so there is something wrong with this connection string. Any help regarding that is highly appreciated.
EDIT
Reading from here SQL Server Connection Strings and following EF Db first or Model first connection string example
<add name="ConnectionStringName"
providerName="System.Data.EntityClient"
connectionString="metadata=res://*/ ContextClass.csdl|res://*/ ContextClass.ssdl|res://*/ ContextClass.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ServerName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True"" />
This is what I am using according to above example
<add name="ProjectEntities" connectionString="metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Integrated Security=False;User Id=username#servername;Password=kenth$$123;MultipleActiveResultSets=True"
" providerName="System.Data.EntityClient"/>
It says
Keyword not supported 'data source'
I had the same problem when specified EF connection string on the Azure Portal in Application Service settings (Application settings -> Connection strings).
To fix it:
Replace " with "
Specify connection string type as Custom but not as SQL Database.
Also, as I can see you do not have Initial Catalog in your latest example. You need to add it and specify your database in this parameter.
Finally your connection string for application settings in Azure portal should look like this:
metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Initial Catalog=<your database>;Integrated Security=False;User Id=username#servername;Password=kenth$$123;MultipleActiveResultSets=True";

How to solve "Login failed for user 'domain\Username'" in SQL Server 2008 R2

I have a website where I need to fetch data from a SQL Server 2008 R2 database. But I'm getting an error
Login failed for user 'domain\Username'
I googled for it then I get that to change property of SQL Server -> Properties -> Security -> Server authentication to SQL Server and Windows authentication mode only I'm still getting the same error. I don't want to use ID and password in connection string
My connection string:
<add name="ConnectionString"
connectionString="Data Source=servername;Initial Catalog=databasename;Integrated Security=True"
providerName="System.Data.SqlClient" />
Please help me.
add user id and passsword
or
1) Go to Server Explorer tab on VS
2) In Data Connections right click (click on properties) on your db
3) copy Connection String

Strange MVC Error Using GearHost

When I run my program on my local machine it works just fine. However, when I try to interact with my database via GearHost, I get this nugget of an error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified.
Everywhere I have gone, the forums say it is a connection string error.
If that is the case here is my connection string:
<add name="GameStoreEntities" connectionString="metadata=res://*/Models.GamesModel.csdl|res://*/Models.GamesModel.ssdl|res://*/Models.GamesModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\GameStore.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
If anyone has any idea about what is wrong with the connection string, I would appreciate your feedback.
GearHost does not seem to have support for LocalDB.
So you would have to create a database on their admin panel and use the credentials of the default user that is created to write your connection string. You could also create a new user for the database and use those credentials instead.
Either way your new connection string should be something like this
<add name="GameStoreEntities"
providerName="System.Data.SqlClient"
connectionString="Data Source=DATABASEHOST;Initial Catalog=DATABASENAME;Integrated Security=False;User Id=USERNAME;Password=PASSWORD;MultipleActiveResultSets=True" />
where you just replace the DATABASEHOST with the hostname for the database. You would see this at the bottom of the page after creating the database.
You get the PASSWORD by clicking the uncover(eye) button after creating the database
If you have data in the localDB that you want to sync to the database you have created on GearHost you can use the Data Comparison and Schema Comparison tools in Visual Studio to update the target database.

Defining connection string using windows authentication across domains to access SQL server

I have problems defining the connection string in a windows service application. The SQL server and windows service are on different domains, and thats the problem. However, i know this is possible, because when using runas.exe in the terminal with this parameters there is no problem.
%windir%\system32\runas.exe /noprofile /netonly /user:DOMAIN1\%USERNAME% "ssms -nosplash -S SQLServerName -E"
So the problem should be in my connection string. How can i modify my connection string to access the server the same way? My connection string now looks lite this:
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/DataAccess.MyDatabase.csdl|res://*/DataAccess.MyDatabase.ssdl|res://*/DataAccess.MyDatabase.msl;
provider=System.Data.SqlClient;provider connection string="data source=SQLServerName;
initial catalog=MyDatabase;Trusted_Connection=yes;User Id=DOMAIN1\USERNAME;Password=*****;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
UPDATE
Seams like it isnt possible to replicate the runas.exe command exactly. I tried to use impersonation like podiluska explained. But, this only works if the user can run on the current domain. In my case i cant, I want to send the windows credentials as parameters when connecting to the database, because that user cannot log on in the current domain. Can anybody confirm that this is impossible?
You need to use impersonation - either in the IIS app pool, or by adding a line to the web.config
<identity impersonate="true" userName="DOMAIN1\UserName" password="****" />
(and remove the user id / password entries from the connection string

login failed connecting to SQL Server with AttachDbFilename and User Instance

I am developing ASP.NET 2.0 application using SQL Express 2005. I have attached my database with the application.
The Connection string:
<add name="WCMIRConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="\App_Data\WCMIR.mdf";Integrated Security=True;Trusted_Connection=no;User Instance=True" />
When trying to connect the following error appears :
Cannot open database "dp-name" requested by the login. The login failed.
Login failed for user 'Machine\useID'.
How can this error be resolved?
First I think the connection string should be with |App_Data| not \App_Data\
Second Make sure that this user has permission on this folder and on this DB
You shouldn't need the AttachDbFileName if your database is already attached, but you should include InitialCatalog to indicate which database you would like to connect to.
Problem Solved
Connection string must be like :
Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|DB.MDF;" +
"Integrated Security=True;User Instance=True";
Just try to use "|" instead of backslash in your code.