【问题标题】:Can't connect to SQL user?无法连接到 SQL 用户?
【发布时间】:2014-03-17 05:54:55
【问题描述】:

伙计们,我正在尝试在我的 PC 上本地托管一个 asp 网站。现在该网站在 VS2012 的调试模式下完美运行。现在我已经将它发布并托管在 IIS 服务器 7.5(使用 windows 7 x64)上,现在当我浏览 localhost 时,会显示我网站的默认登录页面。当我输入登录凭据并按登录按钮时,出现以下错误:(无论凭据是否正确都会产生错误)

Server Error in '/' Application.
Login failed for user 'WORKGROUP\SILICON-PC$'.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'WORKGROUP\SILICON-PC$'.

Stack Trace:


[SqlException (0x80131904): Login failed for user 'WORKGROUP\SILICON-PC$'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352431
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +69
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +30
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +317
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +891
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +518
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110
System.Data.SqlClient.SqlConnection.Open() +96
Logon.LookupUser(String Username) +87
Logon.Button1_Click(Object sender, EventArgs e) +48
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9752490
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +196

这是连接字符串,我在网络配置中使用。

<add name="ST" connectionString="Data Source=000.000.0.000,1433;Network Library=DBMSSOCN;Initial Catalog=STDB;User ID=user;Password=pass" />

Data Source 我的 PC 的 IP 和 SQL 凭据是正确的,我已经检查过了。另外,我有一个使用相同凭据并且运行良好的桌面应用程序。 我还在 IIS 管理器的应用程序池标识中选择了NetworkService

可能是什么问题?

【问题讨论】:

  • 域账户WORKGROUP\SILICON-PC$ 存在吗?如果是,那么该帐户是否有权访问数据库。 “我还选择了 NetworkService”这将不起作用,因为您在连接字符串中选择了 sql server 身份验证而不是 windows (SSPI)
  • 您确定您使用的是正确的连接字符串吗??
  • @Rajatbanerjee 是的,我的电脑名为 Silicon-PC。它已安装 SQL Server。我应该怎么做才能使网页直接连接到 SQL Server?如果我们想直接连接到SQL server,我们不应该选择NetworkService吗?
  • @VincentDagpin,这有关系吗?因为用户得到一个身份验证错误,只有当他能够访问服务器时才会出现?或者....
  • @VincentDagpin 我用 0 掩盖了我的 PC 的 IP。

标签: c# asp.net sql web-config connection-string


【解决方案1】:

为您的机器创建登录名,并添加读取/写入数据库的权限:

-- Create login
USE [master]
GO
CREATE LOGIN [WORKGROUP\SILICON-PC$] FROM WINDOWS
GO


-- Add it as user of YourDatabase, and assign rights to read/write data using roles
USE [YourDatabase]
GO

CREATE USER [silicon-pc] FOR LOGIN [WORKGROUP\SILICON-PC$] WITH DEFAULT_SCHEMA=[dbo]
GO

ALTER ROLE db_datareader ADD MEMBER [silicon-pc] 
go

ALTER ROLE db_datawriter  ADD MEMBER [silicon-pc] 
go‏

您还可以使用登录名/密码组合、另一个 Windows 帐户或基于证书的身份验证来使用直接模拟。

【讨论】:

    猜你喜欢
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    相关资源
    最近更新 更多