简体   繁体   中英

Connect with SQL Server 2008 Express using Winforms (C#)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM