且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Web应用程序连接到SQL Server 2008数据库

更新时间:2023-02-22 13:26:50

为了连接到数据库,你需要使用 SqlConnection [ ^ ](看看示例最后)。



要获得正确的连接字符串,请访问 http://www.connectionstrings.com/sql-server-2008 [ ^ ]



使用本地Sql Server实例时,您可以定义计算机的名称,也可以使用它来引用它。 (点)这是连接字符串中本地计算机的快捷方式。



不确定为什么要尝试更改任何用户。当您连接到数据库时,您要么使用Sql Server用户身份验证,这意味着您使用密码定义用户名以连接到数据库或您使用Windows身份验证,这再次意味着您的当前凭据将用于连接。



如果您使用Windows身份验证,请注意IIS使用的凭据用于连接。例如,看看在IIS 7.0上为ASP.NET网站设置SQL Server 2008 [ ^ ]
In order to connect to the database, you need to use a SqlConnection[^] (have a look at the example in the end).

To get the connection string right, visit http://www.connectionstrings.com/sql-server-2008[^]

When you use local Sql Server instance, you can define a name of the computer or you can refer it using . (dot) which is a shortcut for local computer in connection strings.

Not sure why you''re trying to alter any user. When you connect to the database, you either use Sql Server user authentication which means that you define a user name with a password in order to connect to the database or you use windows authentication which again means that your current credentials will be used for the connection.

If you use Windows authentication, notice that the credentials that are used with IIS are used for the connection. For example, have a look at Setting up SQL Server 2008 for an ASP.NET website on IIS 7.0[^]


http://blog.sqlauthority.com/2008/11/02/sql-server-fix-error-login-failed-for-user-username-the-user-is-not-associated -with-a-trusted-sql-server-connection / [ ^ ] br />




请参考以上链接。
http://blog.sqlauthority.com/2008/11/02/sql-server-fix-error-login-failed-for-user-username-the-user-is-not-associated-with-a-trusted-sql-server-connection/[^]


Please refer above link.