我有一個計劃,將使用應用程序角色將數據寫入到SQL Server 2005。應用程序角色連接到SQL Server與「登錄失敗」錯誤
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是 未處理由用戶代碼
消息= 「登錄失敗,用戶 'DOMIAN \用戶名'。」來源= 「淨 SqlClient數據提供程序。」
錯誤碼= -2146232060類= 14
LineNumber上= 65536數= 18456
程序= 「」 服務器= 「服務器B」
狀態= 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的數據流, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)
在System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布爾 enlistOK)
在System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,字符串NEWPASSWORD, 布爾ignoreSniOpenTimeout,Int64類型 timerExpire,SqlConnection的 owningObject)
在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(字符串 主機,串NEWPASSWORD,布爾 redirectedUserInstance,SqlConnection的 owningObject,SqlConnectionString connectionOptions,Int64的timerStart)
在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection的 owningObject,SqlConnectionString connectionOptions,串NEWPASSWORD, 布爾redirectedUserInstance)
在系統.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,SqlConnectionString connectionOptions,Object providerInfo,String newPassword, SqlConnection owningObject,Boolean redirectedUserInstance)
在System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 選項,對象poolGroupProviderInfo, 池類DBConnectionPool,的DbConnection owningConnection)
在System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(的DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory。的getConnection(的DbConnection owningConnection)
在System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory的)
在System.Data.SqlClient.SqlConnection.Open()
在ADSK.PSEB.ACRSubmitComponent。 ACRSubmit.backgroundUploadWork_DoWork(對象 發件人,DoWorkEventArgs e)如 C:\ Documents和 設置\ lvlu \桌面\穆德\上傳\ ADSK.PSEB.ACRSubmitComponent \樹幹\ ADSK.PSEB.ACRSubmitComponent \ Form1.cs中:行 at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventAr GS E)
在System.ComponentModel.BackgroundWorker.WorkerThreadStart(對象 參數)