2011-08-17 56 views
1

我正在使用Visual Studio 2008附带的构建的SQL Server 2005在我的项目中。 这是我的连接字符串。更改Visual Studio 2008附带的SQL Sever 2005的身份验证模式

SQLConnection oConnection = new SQLConnection("Data Source=.\SQLExpress Initial Catalog=Fas"); 

当我尝试打开像oConnection.open连接()我越来越像错误“登录失败,该用户。用户未与可信连接关联的。” 通过一些谷歌搜索,我得到了我正在使用Windows身份验证模式的想法。那么我怎么能把它改成混合模式认证呢?我没有在我的系统上安装单独的sqlserver。 它与视觉工作室2008相同

回答

0

它是一个 “单独的SQL Server”,Visual Studio的只是安装它。它与您从Microsoft.com获得的SQL Express安装没有区别。

你会想要启动SQL Express Management Studio。它应该在开始菜单中的“Microsoft SQL Server 2005”下。连接到SQLEXPRESS实例;一旦连接,在“对象资源管理器”下,右键单击服务器本身,点击属性,然后选择安全。

使用混合模式不是安全实践的最佳选择,因为它需要将用户名和密码存储在某个连接字符串中。如果您使用的是Web服务器项目,最好的办法是根据您的需要将NETWORK SERVICE作为数据读取器/写入器或db_owner添加。

0

而不是。使用服务器名称本身。如果它是本地机器,这将是您的机器名称。

在年底可信连接的连接添加

Integrated Security=True 

。所以,你最终的连接应该是这样的

SQLConnection oConnection = new SQLConnection("Data Source=MYPC-NAME\SQLExpress; Initial Catalog=Fas;Integrated Security=True"); 
+0

但是,当我使用集成安全,它显示无效关键字集成安全.. – 2011-08-17 12:38:39

+0

你检查拼写? – 2011-08-17 12:39:45

0

您可以添加以下到您的连接字符串将指定SQL用户:如果你想使用

User ID=myUserId;Password=myPassword;

SQLConnection oConnection = new SQLConnection("Data Source=.\SQLExpress;Initial Catalog=Fas;User ID=myUserId;Password=myPassword;");

Windows身份验证用户,请添加:

Integrated Security=true;

SQLConnection oConnection = new SQLConnection("Data Source=.\SQLExpress;Initial Catalog=Fas;Integrated Security=true;");

相关问题