[英]Accessing sql 2008 database through visual studio 2010 C#
Hey guys I have what should be a simple question, but I am new to C# so I am having just a little problem. 大家好,我有一个简单的问题,但是我是C#的新手,所以我有一个小问题。 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. 与我的SQL Server我正在使用Windows身份验证...如果有帮助。
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? 我已经看到我可能需要在sql设置中打开远程访问,任何人都可以告诉我该怎么做吗?
Thanks! 谢谢!
Your connection string should specify that integrated authentication (Windows authentication) has to be used. 您的连接字符串应指定必须使用集成身份验证(Windows身份验证)。 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. 否则,它将尝试执行SQL用户/密码身份验证,默认情况下该功能在SQL Server上已禁用,并且如果启用,则不会针对Windows用户进行身份验证。
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). 仅当您的应用程序和SQL Server Express实例不在同一台计算机上时才需要远程访问(这就是为什么示例连接字符串在此处的服务器名称带有.
,该名称代表本地服务器)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.