1

Possible Duplicate:
Changing SQL Server settings programmatically

To setup a network connection between client C# application and SQL Server 2008 R2 I know what should manually do, my problems is how to do following steps in the C# code!

  1. Set TCP/IP protocol Enabled for a server instance like MSSQLSERVERR2.
  2. Restart my SQL Server engine.

    I can do the other steps by SQL queries:

  3. Add User and grant admin permission.

    CREATE LOGIN momtahen 
    WITH PASSWORD = '123'
    
    EXEC master..sp_addsrvrolemember @loginame = N'momtahen', 
                                     @rolename = N'sysadmin'
    
  4. Set mixed authentication mode for my SQL Server.

    EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', 
    N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2
    

I need C# code or SQL query that I could execute using C#.

Also I have to mention that I have seen following question and no help yet!

Thanks to them by the way. So any Idea?

Community
  • 1
  • 1
Reza Ameri
  • 1,803
  • 3
  • 24
  • 32
  • The options seem to have been discussed here already: [Changing SQL Server settings programmatically](http://stackoverflow.com/questions/2266697/changing-sql-server-settings-programmatically) It would help if you can explain why none of the other questions are helpful, and also if you're installing SQL Server then the suggestion to use a silent installation with a configuration file would be an alternative. – Pondlife Oct 09 '12 at 12:33
  • I couldn't find or write the C# code! – Reza Ameri Oct 10 '12 at 09:13
  • I found the code, I'll post it in [here](http://stackoverflow.com/questions/2266697/changing-sql-server-settings-programmatically) since this thread is closed. – Reza Ameri Oct 10 '12 at 12:56

0 Answers0