I am currenty creating SQLWorker class with various methods which excutes various sql commands as part of a wider framework. I have a method which is used to execute a sql scripts. as whon below:
public object ExecuteScript(string sql, ExecutionType executionType = ExecutionType.NonQuery,
int statementTimeout = 1800)
{
using (var connection = new SqlConnection(ConnectionString))
{
connection.InfoMessage += (sender, args) =>
_infoMessageText.AppendLine(args.Message);
var server = new Server(new ServerConnection(connection));
server.ConnectionContext.StatementTimeout = statementTimeout;
switch (executionType)
{
case ExecutionType.NonQuery:
return server.ConnectionContext.ExecuteNonQuery(sql);
case ExecutionType.Scalar:
return server.ConnectionContext.ExecuteScalar(sql);
case ExecutionType.Reader:
return server.ConnectionContext.ExecuteReader(sql);
}
}
return null;
}
I am currently getting the error: Argument 1: cannot convert from 'System.Data.SqlClient.SqlConnection' to 'Microsoft.SqlServer.Management.Common.IRenewableToken'
the particular line is
var server = new Server(new ServerConnection(connection));
The ServerConnection Class seem to expect a parameter of IRenewableToken but it has constructor that accepts a SqlConnection parameter.
I am not sure what I missing I beleive I have the correct NugetPackages and have the following using statements
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
Any ideas on what I am missing here?