ASKA
ASKA

Reputation: 21

How to access database in SQL Server 2008 from another computer

I need to access database in another computer using c#...I am using connection string with IP address for accessing database and also changed firewall setting but it shows error as follows

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

I m using this connection string

SqlConnection con = new SqlConnection("data source=192.168.1.12,1063;initial catalog=trinity;integrated security=false;network library=DBMSSOCN");

Upvotes: 2

Views: 5447

Answers (2)

hollystyles
hollystyles

Reputation: 5039

This is actually quite a large topic involving: Networking, Authentication, Authorization and Permissions. Quick checklist:

  1. Open port 1433 on local firewall where SQL Server is running.
  2. Open SQL Server Configuration Manager on the local machine where SQL Server is running and enable TCP connections.
  3. Add a Windows Login or SQL Account user and grant permissions to the database. DON'T USE THE SA ACCOUNT TO CONNECT REMOTELY EVER!.

In your connection string you have Integrated security=false;, so you need to provide User ID=mysqlserveruserid;Password=mysqlserverpassword; parameters in your connection string instead. If you change Integrated security=true; your Windows credentials will be used.

Also why the IP Address? Do you not have network name resolution on your network? e.g. DNS or WINS.

Is SQL Server running as the default instance or does it have a named instance? If it's a named instance (would have been a choice taken when installing SQL Server) You will need Data source=computername\sqlserverinstancename;

More detailed information on all these aspects can be found on MSDN https://msdn.microsoft.com/en-us/library/ms345332.aspx

Upvotes: 1

Related Questions