Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use a trusted connection (SSPI) with the SQLDMO API?

I am using the DMO API via .NET to provide an alternative interface to job scheduling functionality on 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-listed form (SQL Server authentication with uid/pwd provided) but I would also like to provide an option to authenticate as a trusted user (aka SSPI, Trusted Connection)

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

Note: The SQLServerClass.Connect method does not seem to have any overloads, I already tried to pass null values for the user id and password to no avail and the Googles has not been helpful yet. Any ideas?

like image 400
Paul Sasik Avatar asked Feb 24 '23 15:02

Paul Sasik


2 Answers

From the documentation:

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

[...]

Use the Login and Password arguments to specify values used for SQL Server Authentication. To use Windows Authentication for the connection, set the LoginSecure property to TRUE prior to calling the Connect method. When LoginSecure is TRUE, any values provided in the Login and Password arguments are ignored.

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

like image 177
Heinzi Avatar answered Feb 28 '23 05:02

Heinzi


Sure, you can use the LoginSecure property:

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

(actually, I don't remember if you must pas null or empty strings...)

like image 35
Simon Mourier Avatar answered Feb 28 '23 04:02

Simon Mourier