Change the authentication mode for SQL Sever 2005 that comes with visual studio 2008
I am using in built sql server 2005 wh开发者_开发技巧ich comes with visual studio 2008 in my project. This is my connection string.
SQLConnection oConnection = new SQLConnection("Data Source=.\SQLExpress Initial Catalog=Fas");
When I try to open the connection like oConnection.open() I am getting error like "Login failed for this user. User is not associated with trusted connection." By some googling I get the idea that I am using Windows authentication mode. So how can I change it to mix mode authentication? I dont have separate sqlserver installed on my system. It is same that comes with visual studio 2008
It is a "Separate SQL Server", Visual Studio just installs it for you. There is no difference between it and the SQL Express installation you would get from Microsoft.com.
You'll want to fire up SQL Express Management Studio. It should be under "Microsoft SQL Server 2005" in your start menu. Connect to the SQLEXPRESS instance; once connected, under "Object Explorer", right click the server itself, hit properties, then Security.
Using Mixed Mode isn't the best for security practices since it requires storing a username and password in a connection string somewhere. If you are using a web server project, your best bet would be to add the NETWORK SERVICE
as a data reader / writer, or db_owner depending on your needs.
Instead of . use the server name itself. This would be your machine name if it is a local machine.
Add
Integrated Security=True
in your connection at the end for trusted connection. So your final connection should look like this
SQLConnection oConnection = new SQLConnection("Data Source=MYPC-NAME\SQLExpress; Initial Catalog=Fas;Integrated Security=True");
You can add the following to your connection string which will specify a SQL user:
User ID=myUserId;Password=myPassword;
SQLConnection oConnection = new SQLConnection("Data Source=.\SQLExpress;Initial Catalog=Fas;User ID=myUserId;Password=myPassword;");
If you want to use a Windows Authenticated user, add:
Integrated Security=true;
SQLConnection oConnection = new SQLConnection("Data Source=.\SQLExpress;Initial Catalog=Fas;Integrated Security=true;");
精彩评论