1

I am trying to publish c# windows form application that has around 15 forms, 4-5 datagrids, datasets etc. I have developed this app on my PC and it has database which is developed on SQL server 2012 (not express).

Now I want to run this app on another laptop, which is connected to my network over a LAN. I want this app to run on that laptop but still use the database on my laptop.

On my laptop, the connection string is present in App.config. Here it is :

    <add name="ST" connectionString="Data Source=STI;Initial Catalog=ST;Integrated Security=True" providerName="System.Data.SqlClient"/>

Now how can I change the connection string so it may work on another laptop but still connect to db that is on my laptop?

I hope you understand my question.

Regards.

4
  • You need to point the connectionString to your initial laptop via its IP. Commented Feb 17, 2014 at 10:34
  • if my laptop's ip is for example 192.0.0.1, then how do I go about doing it? Commented Feb 17, 2014 at 10:35
  • And you need to fix your laptop firewall. SQL Ports do not get automatically opened by the sql installer. Commented Feb 17, 2014 at 10:37
  • What about datagrids? will they use this updated connectionstring? I designed them using datagridview designer. Commented Feb 17, 2014 at 10:50

4 Answers 4

2

Use the name of your laptop as bellow

Data Source=myServerAddress;

or use the IP or your laptop:

Data Source=192.0.0.1,1433;

http://www.connectionstrings.com/ is a very good resource for understanding how .NET connection strings work.

Full connectionString:

<add name="ST" connectionString="Data Source=192.0.0.1\SQLEXPRESS;Initial Catalog=ST;Integrated Security=True" providerName="System.Data.SqlClient"/>

Without TrustedConnection:

<add name="ST" connectionString="Data Source=192.0.0.1\SQLEXPRESS;Initial Catalog=ST;User Id=myUsername;Password=myPassword;" providerName="System.Data.SqlClient"/>

You replace Integrated Security=True with User Id=myUsername;Password=myPassword;.

In addition to this, as other answers have said, the server and laptop need to be configured to accept remote connections.

Sign up to request clarification or add additional context in comments.

6 Comments

What about SQL user/pass? on my laptop it uses windows authentication but I don't think it will work on laptop connected over LAN? Can you please provide complete connectionstring?
@ShajeeAfzal Check my answer. It points to connectionstrings.com - the ultiamte ressource for all types of connectionstrings. So you do not have to even bother with this pesky documentation (granted, the connection string details are a little hidden in there). Comes in handy when you need version specific stuff or other database techs.
@TomTom, I also referenced connectionstrings.com
@ShajeeAfzal, I have included a complete connection string without windows authentication. The server would have to have a username and password set up.
What about datagrids? will they use this updated connectionstring? I designed them using datagridview designer.
|
1

You will need to change the Data Source part to be the computer name and the sql instance name, for example:

Data Source=MyLaptop\SQL2012;

And the Initial Catalog should be the database name (I guess in this case it is 'ST')

2 Comments

It should also be noted that the database will need to have permissions setup to allow remote access to it, oterhwise the OP will get an exception.
Oh yes, forgot to mention that - apologies.
1

According to http://connectionstrings.com/ you need to set the Data Source in the connectionstrings to the laptop running the sql server.

Then you also must check the server's configuratoin and - open the necessary ports on your laptop firewall. The sql server installer does not install a firewall rule allowing incoming traffic by default, that has to be manually done.

Comments

0

You Can Use Your IP

Data Source= Your LapTop IP

Comments

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.