I currently moving an application from DMO to SMO and I have stumbled upon a problem.
A have a list with Registred Servers. The user is then supposed to choose one of them and then the application i supposed to connect to the choosen Registred Server.
So when I use this code it all works.
int nPos = 0;
RegisteredServer regServer =SmoApplication.SqlServerRegistrations.RegisteredServers[nPos];
if (regServer ==null)return;
Server srv =new Server(regServer.Name);
if (regServer.LoginSecure ==false)
{
srv.ConnectionContext.LoginSecure =false;
srv.ConnectionContext.Login = regServer.Login;
//Harcoding the SecurePassword
System.Security.SecureString seq = new System.Security.SecureString();
seq.InsertAt(0,'c');
seq.InsertAt(1,'o');
seq.InsertAt(2,'l');
seq.InsertAt(3,'a');
srv.ConnectionContext.SecurePassword = seq;
int nDbCount = srv.Databases.Count;
}
But when I do like this it just wont work:
int nPos = 0;
RegisteredServer regServer =SmoApplication.SqlServerRegistrations.RegisteredServers[nPos];
if (regServer ==null)return;
Server srv =new Server(regServer.Name);
if (regServer.LoginSecure ==false)
{
srv.ConnectionContext.LoginSecure =false;
srv.ConnectionContext.Login = regServer.Login;
srv.ConnectionContext.SecurePassword = regServer.SecurePassword.Copy();
int nDbCount = srv.Databases.Count;
}
So my question is how am I supposed to do this? I don't want to prompt the user for login and password for a server that he/she already registered.
Thanks,
Hugo
I don't use linked servers, but looking at the Object Browser and BOL I didn't see a Copy() method for the SecurePassword property. Have you tried just setting one from the other?
Server srv =new Server(regServer.Name);
if (regServer.LoginSecure ==false)
{
srv.ConnectionContext.LoginSecure =false;
srv.ConnectionContext.Login = regServer.Login;
srv.ConnectionContext.SecurePassword = regServer.SecurePassword;
int nDbCount = srv.Databases.Count;
}
I tried this first and It didn't work so I used the Copy() method instead. And that didn't work either. So I still need help.
|||Anyone get a direction from MS or otherwise for this?|||
Hi Hugo,
You should not have to call Copy -- you should be able to assign SecurePassword directly, like this:
srv.ConnectionContext.SecurePassword = regServer.SecurePassword;
|||That's exactly what I started to do. But that didn't work so I tried the Copy() method and that didn't work either. So I still haven't gone past this problem.
/Hugo
No comments:
Post a Comment