Shajee Afzal
Shajee Afzal

Reputation: 615

How to deploy a C# windows form application that has database on another PC?

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.

Upvotes: 1

Views: 2707

Answers (4)

Sam Leach
Sam Leach

Reputation: 12966

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.

Upvotes: 2

Mohsen Vaziri
Mohsen Vaziri

Reputation: 7

You Can Use Your IP

Data Source= Your LapTop IP

Upvotes: 0

TomTom
TomTom

Reputation: 62159

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.

Upvotes: 1

Rob Aston
Rob Aston

Reputation: 816

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')

Upvotes: 1

Related Questions