1

I am currently writing a windows form application in c#.
I am using Microsoft SQL Server Management 2008 R2 to store my data in the database.
My application work fine when I am using my own laptop because my server name in database is set to localhost.
However, this program will not work if I am trying on other people's laptop (cannot connect to my database).
I want to write a configure file for this program so that the user can access my windows form application anywhere.
I am sure sure how to get it done.
My servername is localhost and this is my SQL connection string in my Form1.cs. Help and example for reference will be appreciated, thanks

myConn = new SqlConnection("Server = localhost; Initial Catalog= dbName; Trusted_Connection = True");

Updated (I don't have password to connect)

   <connsectionStrings>
     <add name="myConn" connectionString="Data Source=PC6\SA;Initial Catalog=dbName;"/>       
 </connsectionStrings>


<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />


</startup>

1
  • 1
    if u can ping ur system from other system then u can connect to the database by changing localhost to your ipaddress or sql server name Commented Sep 22, 2015 at 7:41

1 Answer 1

1

try this code

SQL Server Authentication

<add name="myConn" connectionString="Data Source=PC6\SA;Initial Catalog=dbName;User ID=sa;Password=sa123"/>

Windows Authentication

<add name="myConn" connectionString="Data Source=PC6\SA;Initial Catalog=dbName; />
Sign up to request clarification or add additional context in comments.

4 Comments

Hi Denish, thank you for your quick reply. Just wondering am I adding is this code in the App.config file, and what is PC6\SA ? :/
yes.In the config.PC6/SA would become your ipaddress or sql instance name as @Sachu mentioned.
@Amit, thank you for your respond. I will give it a try :)
I tried this code, somehow I get the An unhandled exception of type 'System.TypeInitializationException' occurred in System.Data.dll

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.