Reputation: 1939
I am trying to make my program, that uses SQL Server, available on another machine. I know that that machine will need the SQL Server Client installed for this to work, but I am wondering if my ConnectionString will work outside of my own PC.
Do I need to attach my Database to the Project? And if so, how could I do that?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\BENESQL;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=123qwe;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Upvotes: 3
Views: 718
Reputation: 2674
Your connection string is pointing at your local machine, change it to:
connectionString="Data Source=<<server name or IP address>>\BENESQL;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=123qwe;"
By default SQL server is not setup to be connected to remotely, even if it's not your LAN. On your server you need to go on to Sql Server Configuration Manager and enable TCP/IP
.
Upvotes: 5
Reputation: 77846
No it will not since it's currently pointing to a local instance of SQL server. You would also need to specify the server ip and port probably in your Data Source
property of connection string
Data Source=<IPAddress>\BENESQL;Initial Catalog=Northwind;
See https://www.connectionstrings.com/sql-server/ for more information
Upvotes: 0
Reputation: 948
Your data source must contain either other PC name or IP address, so instead of:
Data Source=.\BENESQL
you need something like:
Data Source=123.123.123.123\BENESQL
Also you need to remember to add exceptions to firewall etc.
Upvotes: 8