Can I use a reliable connection (SSPI) with the SQLDMO API?

I am using the DMO API via .NET to provide an alternative interface for job scheduling functions on the SQL Server 2000 Agent. The working code looks something like this:

using SQLDMO; internal class TestDmo { public void StartJob() { SQLServerClass sqlServer = new SQLServerClass(); sqlServer.Connect("MyServerName", "sql_user_id", " p@ssword "); // no trusted/SSPI overload? foreach (Job job in sqlServer.JobServer.Jobs) { if (!job.Name.Equals("MyJob")) continue; job.Start(null); } } } 

Everything works in the above form (SQL Server authentication with uid / pwd provided), but I would also like to provide authentication as a trusted user (e.g. SSPI, Trusted Connection).

Is this possible in the DMO API? If so, how?

Note. The SQLServerClass.Connect method does not seem to have overloads, I already tried to pass null values ​​for the user ID and password to no avail, and Google was not useful. Any ideas?

+4
source share
3 answers

From the documentation :

object.Connect ([ServerName], [Login], [Password])

[...]

Use the Login and Password arguments to specify the values ​​used for SQL Server authentication. To use Windows authentication to connect, set the LoginSecure property to TRUE before calling the Connect method. If LoginSecure is TRUE, any values ​​specified in the Login and Password arguments are ignored.

Thus, before calling Connect, you must set the LoginSecure property to true . Then it does not matter what values ​​you pass for the last two parameters.

+4
source

Of course, you can use the LoginSecure property:

 SQLServerClass sqlServer = new SQLServerClass(); sqlServer.LoginSecure = true; sqlServer.Connect("MyServerName", null, null); 

(in fact, I don't remember if you should have empty or empty lines ...)

+2
source

Set SQLServerClass.LoginSecure = true and leave the username and password blank.

Check here for more information. I just noticed that LoginSecure out of date. Apparently SQL-DMO has been superseded by SMO.

+2
source

Source: https://habr.com/ru/post/1346269/


All Articles