简体   繁体   English

无法连接到SQL用户?

[英]Can't connect to SQL user?

Guys I am trying to host locally a asp website on my PC. 伙计们,我正在尝试在我的PC上本地托管一个ASP网站。 Now the website works perfectly in VS2012's debug mode. 现在,该网站可以在VS2012的调试模式下完美运行。 Now I have published it and hosted it on IIS server 7.5 (using windows 7 x64), now when I browse localhost, the default login page of my site is shown. 现在,我已发布它并将其托管在IIS服务器7.5(使用Windows 7 x64)上,现在当我浏览localhost时,将显示站点的默认登录页面。 When I put login credentials and press login button, I get the following error : (error is generated whether the credentials are correct or not) 当我放置登录凭据并按登录按钮时,出现以下错误:(无论凭据是否正确,都会生成错误)

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

This is the connection string, I am using in web config. 这是我在Web配置中使用的连接字符串。

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

where Data Source has my PC's IP and SQL credentials are correct, I have checked. 我检查了Data Source在哪里拥有我的PC的IP和SQL凭据。 Also, I have a desktop application that is using the same credentials and is working perfectly. 另外,我有一个使用相同凭据的桌面应用程序,并且运行良好。 I have also selected NetworkService in my application's pool identity from IIS manager. 我还从IIS管理器的应用程序池标识中选择了NetworkService

What could be the problem? 可能是什么问题呢?

Create login for your machine, and add rights to read/write your database: 为您的计算机创建登录名,并添加读取/写入数据库的权限:

-- 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‏

Also you can use direct impersonation using login/password combination, another windows account, or certificate-based auth. 您还可以使用通过登录/密码组合,另一个Windows帐户或基于证书的身份验证的直接模拟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM