RE: Change SQL Server Authentication method programmatically

From: Christian Donner (ChristianDonner_at_discussions.microsoft.com)
Date: 05/29/05

  • Next message: Wayne Snyder: "Re: SQL Server EM/Query Analyzer Access"
    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


  • Next message: Wayne Snyder: "Re: SQL Server EM/Query Analyzer Access"

    Relevant Pages

    • Re: Default website stops
      ... "Absar" schreef in bericht ... >> hangs if SMTP service hangs then I have to again restart Server. ... >> website stopped for which i have to start IIS service. ...
      (microsoft.public.windows.server.sbs)
    • RE: Default website stops
      ... If i remove SSL 443 from default website property & restart server then ... > website stopped for which i have to start IIS service. ...
      (microsoft.public.windows.server.sbs)
    • Re: Mail Queues
      ... I force conection and then restart Server. ... hours early I recive call from Admin whos domain is in mail stuck ...
      (microsoft.public.exchange.admin)
    • Duplicate email 39 times problem
      ... Our server had this problem after installed exchange SP2 and turn on the ... The duplicate email will received on every (00:00 ... sometimes the problem still continue after I restart server. ...
      (microsoft.public.exchange.admin)