TheKhanSoft
TheKhanSoft

Reputation: 21

Can't access SQL Server through network

I have wrote a database program which I will run from different computer and database will be on a server, i.e. I have SQL Server on my computer which has IP address 192.168.11.55 and port enabled for SQL Server is 1433. When I try to access/login I get the following error.

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.

When I try to connect from my own computer I does work.

This is the database connection class

class DBConnection
{
    public static SqlConnection conn;

    public static SqlConnection openconn()
    {
        if (conn == null)
        { 
            conn = new SqlConnection("data source=tcp:192.168.11.55,1433;initial catalog=SMS_DB;integrated security=sspi");
            //I tried below code as well
            //conn = new SqlConnection("data source=tcp:KASHIFAHMAD-PC,1433;initial catalog=SMS-AWKUM;integrated security=sspi");
        }

        if (conn.State!=ConnectionState.Open)
        {
            conn.Open();
        }
        return conn;
    }
}

Upvotes: 0

Views: 2581

Answers (3)

jayess
jayess

Reputation: 56

Have you enabled the TCP/IP names pipes option in SQL Configuration manager on the server?

Upvotes: 0

Ajay2707
Ajay2707

Reputation: 5798

There have many reason for this. First you test that server response you via.

Window + Run - >type cmd  -> type ping ipaddress -t

Then check response comes or time-out comes.

If response comes, then via SSMS (management sudion), check to connect.

If this will ok, then reconnect with your app.

Still if you have issue, then use SQlserver Data connect wizard from tool.

Connect it and save in web.config.

If all is well , then remove SQLserver data connection and its entry in web.config.

Definately this will help you.

Upvotes: 0

Andrey Korneyev
Andrey Korneyev

Reputation: 26846

There are many possible reasons, mostly on connectivity.

Make sure that firewall on your machine is not blocking 1433 port from incoming connections.

If your server is SQL Server Express - make sure it is configured to accept remote connections (this is disabled by default in SQL Express, it listens local connections only).

See here or here for example how to enable SQL Express to accept remote connections.

Upvotes: 1

Related Questions