I am creating the database from coding in Winforms (C#) and also run the script for creating the tables.
In short I create the database using the Winforms (C#) in SQL Server Express.
But when I run my application I get this error :
Cannot open database '' requested by the login. the login failed. login failed for user 'KETAN\admin'.
My connection string:
Server=.\SQLEXPRESS;Integrated Security=True;database=mydatabasename;User Id=myusername;Password=mypassword;
Any help would be appreciated.
If you have both
Integrated Security=True;
and
User Id=myusername;Password=mypassword;
in your connection string, then the Integrated Security wins and the specific user and password are ignored, and the connection is attempted with your current Windows credentials (KETAN\admin) and that doesn't seem to work
So just change your connection string to:
Server=.\SQLEXPRESS;database=mydatabasename;User Id=myusername;Password=mypassword;
Now, your specific user and its password will be used to connect to SQL Server, and if those are correct, you should be able to connect just fine
Related
I know this is an answered question , however I have tried all the steps mentioned
like:
In SQL Configuration manager have Enabled TCP/IP,Shared Memory and Named Pipes.
Restarted the SQLSERVER
In Services.msc I have restarted SQLSERVER and SQL Server Agent
Added port 1433 in firewall's Inbound rule
Restarted PC number of times
Even Registered Local Server in SQL Server Management tools
I can open SQL Server Management tools
It was working fine and now its not. However I am able to login , then I cannot do any work on it, it gives me an error as :
Tried all the steps mentioned in the accepted answer HERE
I have some other application accessing same SQL Server and they are working fine.
My Connection string :
public SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Database=RMS_EXPRESS;Integrated Security=True;User Id=sa;Password=xxxxxx");
I also tried with the following connection string
Data Source=.;Database=RMS_TS1;Integrated Security=False;User Id=sa;Password=xxxxxxx
It gave me an error. "Login Failed for User 'sa'"
My application and Database are on the same PC
So , please help.
Thanks
You can not setup in your connection string both Integrated Security=true and User Id=sa;Password=xxxxxx
Integrated Security = true means it is using windows credentials (of the user the application is running into). A database connection cannot use both windows AND SQL Server authentication.
You should either:
Use Integrated Security=true and do not specify User Id nor password. This would use windows authentication.
Use Integrated Security=false or remove it althogether and specify both User Id and Password. This would use SQL Server user/password authentication.
Besides that, there was an adittional problem, originally you put Data Source=.\SQLEXPRESS but had to access default instance via Data Source=. which caused that error.
Allow Remote Connections enabled under Connections in SQL Server Properties.
Connecting to SQL Server with a SQL username and password is no problem at all.
These scenarios work just fine:
from C# code using SqlClient in ASP.NET / MVC
with ssms
with Visual Studio Connection Properties Wizard
For example, this works in an MVC project:
new SqlConnection("Server=DB1;Database=testdb;User Id=testuser;Password=testuser1;").Open();
But this identical code fails when run in a desktop application project. It causes the following inner exception error:
user name or password is incorrect
(yes there is a space between user and name)
I've tried:
making sure the protocols are right in SQL Config Manager.
opening up ports in the firewall on client and server.
connecting to another database to see if it's the database and not the client.
the NuGet version of SqlClient.
restarting the dev machine and the server.
ensured the Browser SQL service is running.
ensured the main SQL service is set to automatic and is running.
SqlClient, OLEDB, and ODBC along with appropriate connection strings.
Storing the username and password in a separate credentials object.
Specifying Integrated Security=False in the connection string
But still, nothing.
Why can I connect to SQL Server from everything except from code running in a desktop .NET application? Is something along the way stripping my password out before the connection happens?
Let's try :
data source=DB1;initial catalog=testdb;persist security info=True;user id=testuser;password=testuser1;
User must be a SQL user.
I'm am making a model first website using MVC4 on IIS7.
Currently my connection string looks like this:
<add name="VaultEntities"
connectionString="metadata=res://*/Models.VaultDB.csdl|res://*/Models.VaultDB.ssdl|res://*/Models.VaultDB.msl;provider=System.Data.SqlClient;
provider connection string="
data source=sqlserver\instance;
initial catalog=vault;
integrated security=True;
multipleactiveresultsets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
The connection was auto generated by Visual Studio 2011 when I added the database through the Model First approach. The query works perfectly locally on my development machine. But it dosen't work on the IIS server.
My guess is that this is because my user account on my development machine has access to the SQL server and when IIS tries to access the SQL server its user account gets denied.
In a perfect world I would add a user on the SQL server and use
User Id=myUsername;Password=myPassword;
in my connection string, unfortunately I don't have that option.
Without going into details the dba's are...difficult...to work with.
So is there any way to use my AD account in the connection string to login to the SQL server... Or can I make IIS identify itself as me?
Is there any way to use my AD account in the connection string to
login to the SQL server... Or can I make IIS identify itself as me?
You can get the application pool to use any AD user you want.
I would not recommend using your own username though. How many times have you locked your username in the last 12 months, and what happens when you leave?
Create/use a service AD account, map it in the application pool, and get the DBAs to give DB access to that user, using trusted connection. Sorry, you'll have to talk to the DBAs! :-)
Ok, there is two options.
1. Either you change you application pool identity to one which has AD access to database, this can be done also by using impersonation section in web.config file of your website(Check this link).
2. Either you add sql account to your connection string. As I can see you are using EF connection string, it's a little bit different from standard sql connection string. But still has the same part with sql credentials, just replace integrated security = true to used id =...;password=.... That's all.
Hope this helps.
Hey guys I have what should be a simple question, but I am new to C# so I am having just a little problem. I am using the following connection:
SqlConnection conn = new SqlConnection(#"Server=myservername\SQLEXPRESS;Database=Names;");
I have also tried to include user id and password but my login always fails.
I think this is because I am not really sure what username and password to use.
With my sql server I am using windows authentication... if that helps.
does anyone know which username and password I should be using? or another way to do this?
I have seen that I may need to turn remote access on in my sql settings, can anyone tell me how to do that?
Thanks!
Your connection string should specify that integrated authentication (Windows authentication) has to be used. Otherwise it tries to do SQL user/password authentication, which is disabled on the SQL Server by default, and if enabled it doesn't authenticate against Windows users.
Server=.\SQLEXPRESS;Database=YourDatabaseName;Integrated Security=SSPI;
Remote access is only required if your application and the SQL Server Express instance aren't on the same machine (which is why the sample connection string here has a . for the server name, which represents the local server).
HI people.
I had SQL Server 2005 on Windows XP 32bit and just used this connection string
Server=.\SQLEXPRESS;database=GroupALD; Integrated Security=True"
Now I have Windows 7 64bit and SQL Server 2008 R2 I'm trying to connect database with same string but its shows this error
Cannot open database "GroupALD" requested by the login. The login failed.
Login failed for user 'lester\les'.
Can somebody help me?
I'm using C# and Winforms
Yes, try connectionstrings.com:
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
The error message is pretty clear:
Cannot open database "GroupALD"
requested by the login. The login
failed.
Login failed for user 'lester\les'.
Your user doesn't have a valid login on your new database - it's not a connection-string related issue - you need to create a login for lester\les on your new server and create a user in the GroupALD database for that login.
See : how to create a SQL Server Login
Can you connect to your express edition using SQL Server Management Studio of R2 ?
One workaround i can suggest is to export the database from express to R2 if you can connect to R2 using your connection string .