RE: Change SQL Server Authentication method programmatically
From: Christian Donner (ChristianDonner_at_discussions.microsoft.com)
Date: 05/29/05
- Previous message: Blake Mengotto: "Re: SQL 2000 Security Question"
- In reply to: Jono Price: "Change SQL Server Authentication method programmatically"
- Next in thread: Gert E.R. Drapers: "Re: Change SQL Server Authentication method programmatically"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sat, 28 May 2005 15:33:18 -0700
"Jono Price" schrieb:
> Hi,
> Does anyone here know whether it is possible to change the
> authentication method of a SQL server instance programmatically, rather
> than going through enterprise manager.
>
> I am using SQL-DMO (under C#) for some other things, but the
> documentation is so bad that I can't find out whether what I want to do
> can be done. I have also tried googling but came up empty handed.
>
> I hope that someone can help me.
>
> Cheers
> Jono
This is a VB solution (with SQLDMO). You'll have to translate this to C#
yourself.
On Error GoTo ErrSec
Dim srv As SQLDMO.SQLServer2
Set srv = New SQLDMO.SQLServer2
' integrated security login
srv.LoginSecure = True
' or standard security login
srv.LoginSecure = False
srv.Login = "sa"
srv.Password = "MyPassword"
srv.Connect "MyServer"
' switch to integrated
srv.IntegratedSecurity.SecurityMode = SQLDMOSecurity_Integrated
' or switch to mixed mode
srv.IntegratedSecurity.SecurityMode = SQLDMOSecurity_Mixed
' restart server: shutdown looses the connection and generates an error.
' we catch that error in the error section and restart the server.
srv.Shutdown
Exit Function
ErrSec:
srv.Disconnect
srv.Start (True) ' true reconnects automatically
.
. ' do what has to be done in the db
.
srv.Close: set srv = Nothing
- Previous message: Blake Mengotto: "Re: SQL 2000 Security Question"
- In reply to: Jono Price: "Change SQL Server Authentication method programmatically"
- Next in thread: Gert E.R. Drapers: "Re: Change SQL Server Authentication method programmatically"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|