I'm using the Microsoft.SqlServer.Smo.dll version 9.0.1399.0 in my [NAnt] build process. I'm running on Windows Server 2008 R2. I'm connecting to BOTH Sql Server 2008 R2 (10.5) as well as Sql Server 2008 (10.0).
I'm tweaking the deploy step of one of our project types, and now all of my builds that deploy the Sql job (to the 2008R2 10.5 server are throwing an error saying "ConnectAsUserName was not set".
If I specify the credentials, then I get the error "This Sql Server version (10.5) is not supported".
But if I specify windows authentication, I get the following error: "ConnectAsUserName was not set".
I don't know where else to look, here's the code that I'm using:
using System;
using System.Collections.Generic;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo.Agent;
...
public void Schedule(string sqlServer, string userName, string password)
{
ServerConnection conn = new ServerConnection(sqlServer, userName, password);
conn.LoginSecure = false;
Server server = new Server(conn);
Schedule(server);
}
public void Schedule(string sqlServer)
{
ServerConnection conn = new ServerConnection(sqlServer);
conn.ConnectAsUser = false;
conn.LoginSecure = true;
Server server = new Server(conn);
Schedule(server);
}
public void Schedule(Server server)
{
server.JobServer.Refresh();
JobType.Refresh();
foreach (JobType job in Items)
job.Schedule(server);
}
Also, here's the stacktrace of the error:
Internal Error: Microsoft.SqlServer.Management.Common.PropertyNotSetException Property ConnectAsUserName was not set.
at Microsoft.SqlServer.Management.Common.ConnectionSettings.ThrowIfPropertyNotSet(String propertyName, String str, Boolean checkEmpty) at Microsoft.SqlServer.Management.Common.ConnectionManager.GetWindowsIdentityForConnection() at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
at Microsoft.SqlServer.Management.Common.ConnectionManager.PoolConnect() at Microsoft.SqlServer.Management.Common.ConnectionManager.get_ServerVersion() at Microsoft.SqlServer.Management.Smo.ExecutionManager.GetServerVersion() at Microsoft.SqlServer.Management.Smo.SqlSmoObject.IsExpressSku()
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CheckVersionNotExpress(String uft) at Microsoft.SqlServer.Management.Smo.Server.get_JobServer()
at SqlSchedule.Jobs.Schedule(Server server) at SqlSchedule.Jobs.Schedule(String sqlServer) at NAnt.MVST.Tasks.ImportJobsTask.ExecuteTask(String xmlJobs) at NAnt.MVST.Tasks.ImportJobsTask.ExecuteTask() at NAnt.Core.Task.Execute() at NAnt.Core.TaskContainer.ExecuteChildTasks() at NAnt.Core.TaskContainer.ExecuteTask() at NAnt.Core.Task.Execute()
at NAnt.Contrib.Tasks.TryCatchTask.ExecuteTask() at NAnt.Core.Task.Execute() at NAnt.Core.TaskContainer.ExecuteChildTasks() at NAnt.Core.Tasks.IfTask.ExecuteTask() at NAnt.Core.Task.Execute()
at NAnt.Core.TaskContainer.ExecuteChildTasks() at NAnt.Core.Tasks.IfTask.ExecuteTask() at NAnt.Core.Task.Execute()
at NAnt.Core.TaskContainer.ExecuteChildTasks() at NAnt.Core.Tasks.IfTask.ExecuteTask() at NAnt.Core.Task.Execute()
at NAnt.Core.Target.Execute() at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies) at NAnt.Core.Tasks.CallTask.ExecuteTask() at NAnt.Core.Task.Execute() at NAnt.Core.TaskContainer.ExecuteChildTasks() at NAnt.Core.Tasks.IfTask.ExecuteTask() at NAnt.Core.Task.Execute()
at NAnt.Core.Target.Execute() at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies) at NAnt.Core.Tasks.CallTask.ExecuteTask() at NAnt.Core.Task.Execute() at NAnt.Core.Target.Execute() at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies) at NAnt.Core.Project.Execute() at NAnt.Core.Project.Run()
Also, the MSDN documentation states that this property would be ignored if using Windows Authentication...
I found this post on stackoverflow and I've done all of the stuff in the only answer (even though it's not accepted). Does anyone have anymore ideas?
At first, I went through and had everything setup just like the answer in this post. But after further investigation, I found out that one of my assemblies was coming from the 90 folder instead of 100. Changing that fixed my problem.