How to connect to a remote SQL database using c# windows application?
1.First Ensure that Mixed mode authentication is enabled on your SQL Server.
To Enable Mixed Mode authentication Open ENTERPISE MANAGER
a)Right Click the Server under the SQL Server Group node (eg. (Local (Windows NT)) and select Properties
b) Under the Security tab Select SQL Sever and Windows and click ok.
2.Create a new login
a) Open Enterprise Manager
b)Open SQL Server Group->Server (Local)(Windows NT)
->Security->Login
c)Right Click Login and Select New Login
d)In General Tab Enter a Login Name & Select SQL Server Authentication and enter a password
e)Under Server Roles tab check all the Roles
f)Under Database Access tab Select the database u want to access remotely and select all database roles except denydatareader & denydatawriter.
g)Click ok to finish.
3.Change the Firewall Settings
a)Goto Control Panel and Select Windows Firewall
b)Under the exceptions tab click Add Program button.
c)In the Add a Program dialog click Browse button and select ProgramFiles ->Microsoft SQLServer->MSSQL1.1->MSSQL->Binn->sqlservr.exe
also select ProgramFiles ->Microsoft SQLServer->90->Shared->sqlbrowser
4.In the client machine goto Control Panel & Select Administrative Tools
a)Select Data Sources(ODBC)
b)In the dialog box that opens click ADD button & select SQL Server & Finish
c)Enter the Database name in the name txtbox and enter the server name & click Next
d)Select SQL Server Auth & Click Client configuration Button.In the Dialog box that opens select Named Pipes radiobutton and click Ok.
e)Enter Login ID & Password u created in step 2 and click Next
5.Use the Follwing Connection String in ur c# appln
connectionString=”Data Source=ServerName;Initial Catalog=DatabaseName;User ID=ssss;password=ssss;”
To find ServerName Goto Programs->MicrosoftSQLServer->ServiceManager
Give the User id and password you created in step 2
Now Run the application