简体   繁体   English

如何在连接字符串中设置用户名和密码以连接数据库?

[英]How to set username and password in connection string for connecting to database?

This is my first asp web site and I published the project for web , but now the page with db connection do not work properly , I am sure about user and password what else should I do ?!! 这是我的第一个asp网站,我发布了web项目,但是现在具有数据库连接的页面无法正常工作,我确定用户名和密码还应该做什么?! this is connection string : 这是连接字符串:

<connectionStrings>
    <add name="dbnameConnectionString" connectionString="server=.;database=dbname;uid=user;password=pass;Initial Catalog=dbname;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>

and this sa error that i get : Login failed for user 'WIN-J9A67LA4GER\\hostusername_web'. 这是我得到的一个错误:用户'WIN-J9A67LA4GER \\ hostusername_web'登录失败。

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 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 'WIN-J9A67LA4GER\hostusername_web'.

Source Error: 
[SqlException (0x80131904): Login failed for user 'WIN-J9A67LA4GER\hostusername_web'.]
   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
   System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user) +43
   System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() +41
   System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() +21
   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +57
   System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +33
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +369
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   Lessons.InitialUI() +474
   Lessons.Page_Load(Object sender, EventArgs e) +338
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Your connection string specifying Integrated Security=True which means the connection will use the current window credentials. 您的连接字符串指定Integrated Security=True ,这意味着连接将使用当前的窗口凭据。

So if you want to use the username and password provided by you in connection string then set this property to false . 因此,如果要使用连接字符串中提供的usernamepassword ,则将此属性设置为false

<add name="dbnameConnectionString" connectionString="server=.;database=dbname;uid=user;password=pass;Initial Catalog=dbname;Integrated Security= false" providerName="System.Data.SqlClient"/>

Well the problem is right there in the stack. 那么问题就在堆栈中。

Login failed for user 'WIN-J9A67LA4GER\hostusername_web'

You are setting Integrated Security=True and also specifying a username and password. 您正在设置Integrated Security=True并且还指定了用户名和密码。 From my understanding Integrated Security=True will use the Windows Credentials that the website is running under. 据我了解, Integrated Security=True将使用网站运行所在的Windows凭据。 As answered here . 正如这里的回答。

If you want to specify a SQL Login in your connection string then you need to set that to False. 如果要在连接字符串中指定SQL登录名,则需要将其设置为False。

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

相关问题 使用用户名和密码将用户连接到数据库 - Connecting user to database with username and password 如何在Startup.cs之外设置数据库连接字符串用户名和密码? - How to set DB connection string username & password outside of Startup.cs? 检查数据库的用户名或密码OledDb Connection - Check Database for username or password OledDb Connection 以编程方式检查连接字符串的用户名/密码? - Programmatically checking a connection string username/password? 动态为连接字符串提供用户名和密码 - Dynamically Provide Username and password to Connection String sqlserver连接字符串中的用户名,密码和其他参数 - username , password and other parameters in sqlserver connection string 它创建的编码数据库,并设置用户名和密码 - create database with coding and set username and password for it ms Access数据库受密码保护时如何写连接字符串? - How to write connection string when ms access database is password protected? Sharepoint 使用用户名和密码连接 - Sharepoint connection with a username and password 如何在 .NET Core 中将 kubernetes secret 设置为连接字符串密码? - How to set kubernetes secret as as connection string password in .NET Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM