我正在尝试通过进行自定义活动来使用 CRM 工作流执行 SQL 作业。在我的代码中,一个在线教程让我像这样构造它(在 c# 中):
[CrmWorkflowActivity("A test activity to run SQL Jobs")]
public sealed class ExecuteSQLJob : System.Activities.CodeActivity
{
#region Inputs
[Input("Job Name")]
[Default("BMS_ExtractTransformLoad")]
public InArgument<String> JobName { get; set; }
[Input("Server Connection")]
[Default("HBSSQL2008/MSSQLSERVER")] //<--This String
public InArgument<String> ServerName { get; set; }
[Input("User Name")]
[Default("-----")]
public InArgument<String> UserName { get; set; }
[Input("Password")]
[Default("-----")]
public InArgument<String> Password { get; set; }
#endregion
protected override void Execute(CodeActivityContext context)
{
Server server = new Server(ServerName.Get(context)); //<--Is used here
try
{
server.ConnectionContext.LoginSecure = false;
server.ConnectionContext.Login = UserName.Get(context);
server.ConnectionContext.Password = Password.Get(context);
server.ConnectionContext.Connect();
Job job = server.JobServer.Jobs[JobName.Get(context)];
job.Start();
}
finally
{
if (server.ConnectionContext.IsOpen)
{
server.ConnectionContext.Disconnect();
}
}
}
}
但是,当我尝试运行此工作流时,它会抛出一个错误,指出它无法连接到服务器。(具体来说,错误是在 server.ConnectionContext.Connect() 方法调用上抛出的)。
问题是 serverName 字符串吗?如果是这样,我怎样才能找到要使用的正确服务器名称?
谢谢你的帮助!
编辑: 这里有一些额外的信息......
这是我第一次获得服务器和实例名称的方式:
这是 CRM 工作流程上的错误:
Workflow suspended temporarily due to error: Unhandled Exception: Microsoft.SqlServer.Management.Common.ConnectionFailureException: Failed to connect to server HBSSQL2008.
at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
at ExecuteSQLJob.ExecuteSQLJob.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Inner Exception: System.Data.SqlClient.SqlException: Login failed for user 'rnkelch'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect(WindowsIdentity impersonatedIdentity)
at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
抱歉,我最初没有包含此内容,感谢您迄今为止的帮助