Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to SQL Server on other PC

Tags:

c#

sql-server

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>
like image 229
Benedikt J Schlegel Avatar asked Jul 27 '26 17:07

Benedikt J Schlegel


1 Answers

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.

like image 174
Piotr Wojsa Avatar answered Jul 29 '26 06:07

Piotr Wojsa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!