应用程序角色与“登录失败”错误连接到SQL Server

我有一个使用应用程序角色将数据写入SQL Server 2005的程序。

using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
   SqlCommand sqlCommand = new SqlCommand();
   sqlCommand.Connection = sqlCon;
   sqlCommand.CommandType = CommandType.Text;
   sqlCommand.CommandText = "";
   sqlCommand.CommandText = "EXEC sp_setapprole 'name','password';";
   sqlCommand.CommandText += sqlComm;
   sqlCommand.CommandTimeout = 300;
   sqlCon.Open();

   int res = sqlCommand.ExecuteNonQuery();
}

我使用这段代码来连接SQL Server 2005 ServerA,它运行良好。 然后,我使用相同的代码连接anohter SQL Server 2005 ServerB,与相同的表,应用程序角色,它给出了一个错误。“登录失败的域用户名”以前有人遇到过吗?

System.Data.SqlClient.SqlException由用户代码未处理
Message =“用户'domian username'登录失败。” Source =“.Net SqlClient Data Provider”
ErrorCode = -2146232060 Class = 14
LineNumber = 65536 Number = 18456
Procedure =“”Server =“ServerB”
状态= 1
堆栈跟踪:
在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)
在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)
在System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布尔enlistOK)
在System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout,Int64 timerExpire,SqlConnection owningObject)
在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host,String newPassword,Boolean redirectedUserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions,Int64 timerStart)
在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,SqlConnectionString connectionOptions,String newPassword,Boolean redirectedUserInstance)
在System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity标识,SqlConnectionString connectionOptions,Object providerInfo,String newPassword,SqlConnection owningObject,Boolean重定向用户实例)
在System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection拥有连接)
在System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection,DbConnectionPoolGroup poolGroup)
在System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection拥有连接)
在System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)
在System.Data.SqlClient.SqlConnection.Open()
在C: Documents and Settings lvlu Desktop Mulder Upload ADSK.PSEB.ACRSubmitComponent trunk ADSK.PSEB.ACRSubmitComponent Form1.cs中的ADSK.PSEB.ACRSubmitComponent.ACRSubmit.backgroundUploadWork_DoWork(Object sender,DoWorkEventArgs e) :第897行
在System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
在System.ComponentModel.BackgroundWorker.WorkerThreadStart(对象参数)



也许连接字符串有问题

连接字符串的格式如下所示:

<add name="dbconnect" connectionString="Data Source=localhost;Initial Catalog=db_name;User ID=sa;Password=....." providerName="System.Data.SqlClient" />

参考网站:在使用进程外会话状态的ASP.NET应用程序中与SQL Server的连接问题

链接地址: http://www.djcxy.com/p/9707.html

上一篇: Application Role connect to SQL Server with "Login Failed" error

下一篇: SqlException timeout expired without being reached