establish remote connection to a SQL server instance - sql-server

I am not able to establish remote connections to SQL Server 2008 enterprise edition.
I have followed and implemented a lot of tutorials available. These are the things i have done:
enabled TCP/IP connections in SQL configuration manager.
added a rule to allow inbound connections at port 1433.
allowed remote connections in the properties window of the concerned instance.
But it still gives the error
I am trying to install samples for replication using AdventuresWorks database and i am not able to install the sample.
here is the error i got
Attempting to create the 'ReplData'
share that replication uses as the
working directory.
A subdirectory or file C:\Program
Files\Microsoft SQL
Server\100\Samples\Replica
tion\ReplData already exists. The name
has already been shared.
More help is available by typing NET
HELPMSG 2118.
HResult 0x274D, Level 16, State 1 TCP
Provider: No connection could be made
because the target machine actively re
fused it.
Sqlcmd: Error: Microsoft SQL Server
Native Client 10.0 : A network-related
or in stance-specific error has
occurred while establishing a
connection to SQL Server . Server is
not found or not accessible. Check if
instance name is correct and i f SQL
Server is configured to allow remote
connections. For more information see
SQL Server Books Online.. Sqlcmd:
Error: Microsoft SQL Server Native
Client 10.0 : Login timeout expired.
The publication was created
successfully. You must create a
virtual directory to use Web
synchronization. If you plan to use a
separate Web server, you must run the
Web Synchronization Wizard on that Web
server. (A certificate that supports
SSL must already be installed.)
Do you want to create a virtual
directory named SalesOrders for Web
synchronization on S2NWORKSTATION?
[y,n]

Start the SQL Management Studio
Connect to the server.
Then choose the server in the Object-Explorer and right-click on properties.
Then check the "connections" settings, there you can/have to allow remote connections for this database server.

Are you connecting to a default instance or named instance? If a named instance, then you you should have the sql browser windows service running. Also ensure that remote connections are allowed (I believe this is a different setting than simply turning on TCP/IP).
One tool that could be helpful is PorQryUI (Port Query), it will test to see if the proper ports are open.

I too, had this problem. I solved by doing a couple of things:
1. Make sure the SQL Browser service is started on my local machine
2. Make sure UDP Port 1434 in the firewall is open for outgoing on the local machine
3. Make sure UDP Port 1434 is open in the firewall for incoming on the remote machine.
The UDP Ports are for the SQL Server Browser. Apparently, Visual Studio uses that to detect that the remote server exists.
This Stack Exchange thread was very helpful to me.

Related

Cannot connect to local SQL Server database from a different computer

I get this 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.(provider: SQL Network Interfaces, error: 26, - Error Locating Server/Instance Specific) (Microsoft SQL Server)
I am trying to allow remote access to my local SQL Server database when the user is using my application on a different computer. I've been trying different approaches for weeks and nothing seems to work.
Here is a list of things that I have tried to do:
Changed server property settings to Allow remote connections to the server
Enable TCP/IP and listed 1433 port number in IPALL field
Created inbound rule for SQL Server program, SQL Browser, and port 1433
Temporarily disabled Windows firewall
Again, I know there is a lot of information surrounding this issue, but I feel like I've implemented every solution I could find and nothing is working.
Thank you in advance for your help!
Regarding #1, the allow remote connections to this server checkbox in SSMS does not actually allow remote client clients to connect despite the misleading name. Use SQL Server Configuration Manager (e.g. C:\Windows\SysWOW64\SQLServerManager15.msc, depending on your SQL version) instead. Right-click on SQL Server Network Configuration-->Protocols-->TCP/IP, select Enable, and restart the SQL Server service.

Diagnosing Connection to SQL Server

I'm trying to create an ODBC connection to SQL Server, but when i do, i get error:
Connection failed:
SQLState: '01000'
SQL Server Error: 10060
[Microsoft][ODBC_SQL Server Driver][TCP/IP Sockets] COnnectionOpen (Connect()).
Connection failed:
SQLState: '08001'
SQL Server Error: 17
[Microsoft][ODBC_SQL Server Driver][TCP/IP Sockets] SQL Server does not exist or access denied.
Here's what I've tried:
not a firewall issue: tried with firewall on SQL Server turned off, and client turned off. Also able to telnet 1433 from client and that works fine.
not an access issue: I can login from many different computers, including the SQL Server itself using the account i'm using on client (using SQL Server authentication)
i can ping the hostname and IP address. (i've tried both)
The only thing i can think of is that the client computer is windows server 2003, and has various roles setup:
File Server
Application Server
Terminal Server
Domain Controller
DNS Server
I don't know why these services are setup, but for the time being i can't shut them off. Would it be any of these, and if so, is there a way to disable any of the aspects of them, that might be blocking SQL.
Any advise truly appreciated!
Found the issue. For some reason, even though SQL was not in use on the client, it was installed, and by going to All Programs -> Microsoft SQL Server -> Client Network Utility, i found that the protocal TCP/IP was using port 4717. I have no idea why that port was in use, and even further, i'm not sure why it would even matter - I was just setting up an odbc connection, and not using sql server (on the client) at all. Either way, I changed this to the typical port (1433), and like boom, ODBC connection works like charm!
Is it possible that the server in question has not been configured to use named pipes?
CAUSE
The most common reason that this connection attempt failed is
that this DSN or ODBC data source attempted to make a connection using
the TCP/IP sockets Net-Library, which is Dbmssocn.dll. Because the SQL
Server is not listening for incoming connections for TCP/IP sockets
clients, the connection fails. From ISQL/w, the second error message
stated above would be returned. The OS Error is 10061, and the
function call that failed was ConnectionOpen(connect()).
WORKAROUND
By default, SQL Server will listen for incoming connections
made by Named Pipes clients. Named Pipes is the default IPC mechanism
for clients to connect to a SQL Server version 4.2, 6.0, and 6.5
server. The Named Pipes DLL is Dbnmpntw.dll, and it should be located
in the Windows\System or Winnt\System32 directory. The TCP/IP sockets
netlib DLL is Dbmssocn.dll, and also should be in the Windows\System
or Winnt\System32 directory.The most common resolution to this problem
is to configure the client computer to connect using Named Pipes.
Configuring Named Pipes If the Microsoft Data Access Components (MDAC)
ODBC drivers have been installed on the computer, you can make this
change in the second step of the Create New Data Source wizard.
NOTE: You can download MDAC drivers from:
http://msdn2.microsoft.com/en-us/data/aa937730.aspx To configure the
client, start the Create New Data Source wizard, click the Client
Configuration button, and perform the following steps, based on the
version of the SQL Server ODBC driver you are using:
For SQL Server ODBC Driver version 3.50
Click the Net Library tab and use the drop down list box to set the
default network (Net Library) to Named Pipes.
On the Advanced tab, remove any advanced entries that reference the
server you are connecting to.
Click Done.
For SQL Server ODBC Driver version 3.70
In the Network Libraries section of the Edit Network Library Configuration
dialog box, select Named Pipes.
Click OK.
If you do not have the MDAC ODBC drivers installed, you can use the
SQL Server Client Configuration Utility tool to set the default
Net-Library to Named Pipes. You can install the client utilities from
the SQL Server CD from the i386 directory.
Source: http://support.microsoft.com/kb/195566
By default SQL Native Client seems to look for MSSQLSERVER instance. However, if you use SQLEXPRESS all connections through that will fail.
Very strange, but try installing your SQL Server with MSSQLSERVER instance name - it should work!
To create a new Data source to SQL Server, do the following steps:
In host computer/server go to Sql server management studio --> open Security Section on left hand --> right click on Login, select New Login and then create a new account for your database which you want to connect to.
Check the TCP/IP Protocol is Enable. go to All programs --> Microsoft SQL server 2008 --> Configuration Tools --> open Sql server configuration manager. On the left hand select client protocols (based on your operating system 32/64 bit). On the right hand, check TCP/IP Protocol be Enabled.
In Remote computer/server, open Data source administrator. Control panel --> Administrative tools --> Data sources (ODBC).
In User DSN or System DSN , click Add button and select Sql Server driver and then press Finish.
Enter Name.
Enter Server, note that: if you want to enter host computer address, you should enter that`s IP address without "\\". eg. 192.168.1.5 and press Next.
Select With SQL Server authentication using a login ID and password entered by the user.
At the bellow enter your login ID and password which you created on first step. and then click Next.
If shown Database is your database, click Next and then Finish.
Adding another check point to all the above answers. Valid if you are using a named instance of Sql Server ( ServerName\InstanceName)
Make Sure UDP Port is enabled in Windows Firewall with SQL Server Default UDP Port
Number 1434. If not present create a new incoming rule in Firewall for UDP 1434 Port and restart SQL Server Browser Services in SQL configuration Manager.

Connecting to SQL Server Named Instance from Windows 64bit

I have both java and .net applications running on an app server using Microsoft Windows Server 2003, Enterprise Edition. These are being migrated to another app server Windows 2008 64-bit machine.
All applications connect to the same SQL Server 2005 database, on a named instance.
So far I have tried to move the applications exactly as they are, with no changes in the configuration files, from the old box to the new box.
On the new app server, neither the java nor the .net applications connect to the database (named instance).
JDBC error message: "The connection to the named instance has failed. Error: java.net.SocketTimeoutException: Receive timed out."
The .net error message: "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible."
If I change the DB config to one that is not on a named instance it works on the new app server.
The database is setup correctly, because we were able to connect on the old app server. I can ping the database server from the new app server.
Is there any reason this won't work on the new app server?
java connection string: "jdbc:microsoft:sqlserver://[dbservername];SelectMethod=Cursor;instanceName=[dbinstance]"
.net connection string: "Server=[dbservername]\[dbinstance];Database=Risk_DB;Uid=[user];Pwd=[pwd];"
UPDATE
Per suggestions in the answers, I got the instance port number. I also installed SQL Server Management Studio so I can eliminate my apps as the problem points. From Management Studio, if I use [servername][instancename], I get the message "a network-related or instance-specific error while establishing a connection to SQL Server..." But it works when i use [servername],[port]. Not sure if there's anyway to work around this?
UPDATE #2 Escalated the issue to the infrastructure/server/network team. They disabled windows firewall on the new app server. Presto, now I can connect to [dbservername]\[dbinstance] in Management Studio, and all apps are working using existing configuration files.
Your named instance is going to be running on a different port. Port 1433 (the default for a default instance) is probably open, and the port that the named instance is running on is probably blocked. You can check the port in the error log for the named instance (assuming you can connect locally, in Object Explorer, expand the server, expand Management, expand SQL Server Logs, right-click current, and choose "View SQL Server Log" IIRC), it will say something like this on startup:
Server is listening on [ 127.0.0.1 <ipv4> 3587 ].
That last number is the port number that needs to be accessible from your remote machine and whatever network devices and services it has to go through to get there. If you don't find a line like that, it's possible that TCP/IP is not enabled for the named instance. On that server, go to SQL Server Configuration Manager, expand SQL Server Network Configuration, click on "Protocols for " and make sure TCP/IP is enabled in the right pane. If you have to enable this you'll need to restart SQL Server for it to take effect.
If it is already enabled (or once you enable it and restart the service), you should be able to refresh this view and validate the port that is being used if you right-click TCP/IP, hit properties, and move to the IP Addresses tab. You can see the ports currently being for each IP. Here there will be multiple IPn sections and an IPAll section. For each IP, you can change the "TCP Port" box to a port you want to use (and delete any values in all the "Dynamic TCP Ports" box to 0). Hit Apply and restart the service. This will again require a restart of the service but will allow you to specify a specific port so you can add an exclusion to your firewall (or make use of one that already exists, assuming this server isn't already using that port).
Possible issues:
Firewall maybe blocking connections.
The instance name is not the same as specified in the connection string.
The connection string specifies a different port or SQL Server is running on a different port rather than the default 1433

Unable to connect to SQL Server instance remotely

I’m trying to access the SQL Server instance on my VPS from SQL Server Management Studio on my local machine. It’s not working (the error I’m getting is:
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.
I think this is because I need to configure the database engine to allow remote connections (correct me if I’m wrong!). So I’ve found this step-by-step guide to help me do that: http://www.linglom.com/2009/03/28/enable-remote-connection-on-sql-server-2008-express/ I’ve got to point 10 in the guide and I am now stuck! I don’t have SQL Server Management Studio installed on my VPS. Anyway, this has left me with two options:
Install SSMS
Find another way to do point 10 onwards in the guide without having SSMS installed
I tried installing SSMS on my VPS using the Web Platform Installer but it keeps failing. I don’t know why it’s failing because it doesn’t seem to give a reason why. Does anyone know how I could allow remote connections a different way?
The version of SQL Server installed on my VPS is SQL Server 2008 R2 Express.
Update:
I have tried to disable the firewall on both my laptop and VPS to see if it is a firewall issue. This made no difference to the error message.
Another Update:
Having now been able to install SSMS (I installed directly from the website rather than using the WPI), I have been able to check that the server is configured to allow remote connections (I went to SSMS, connected to the SQL Server instance, right-clicked on the connection, clicked Properties, went to the Connections tab. "Allow remote connections to this server" is already ticked).
SOLUTION
Thanks to everyone for helping me get to this solution! I've finally managed to get it to work! I followed Filip De Vos's advice and opened the ports in the Firewall on my VPS and then I received a different error message. This led me to investigate further and I found that I was using the wrong credentials to login! So I've set a password for the sa user and I've managed to login using that! Thanks again!
To enable mixed authentication you can change the following registry key:
HKLM\Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer\LoginMode
Update the value to 2 and restart the Sql Server service to allow mixed authentication. Note that MSSQL.1 might need to be updated to reflect the number of the SQL Server Instance you are attempting to change.
A reason for connection errors can be a virus scanner installed on the server which blocks sqlserver.exe.
Another reason can be that the SQL Server Browser service is not running. When this service is not running you cannot connect on named instances (when they are using dynamic ports).
It is also possible that Sql Server is not setup to listen to TCP connections and only allows named pipes.
In the Start Menu, open Programs > Microsoft SQL Server 2008 >
Configuration Tools > SQL Server Surface Area Configuration
In the Surface Area Configuration utility, click the link "SQL Server
Configuration Manager"
Expand "SQL Server Network Configuration" and
select Protocols.
Enable TCP/IP. If you need Named Pipes, then you can
enable them here as well.
Last but not least, the Windows firewall needs to allow connections to SQL Server
Add an exception for sqlserver.exe when you use the "Dynamic Port" system.
Otherwise you can put exceptions for the SQL Server ports (default port 1433)
Also add an exception for the SQL Server Browser. (udp port 1434)
More information:
How to: Configure a Windows Firewall for Database Engine Access
Server Connectivity How-to Topics (Database Engine)
As a last note, SqlLocalDB only supports named pipes, so you can not connect to it over the network.
In addition to configuring the SQL Server Browser service in Services.msc to Automatic, and starting the service, I had to enable TCP/IP in: SQL Server Configuration Manager | SQL Server Network Configuration | Protocols for [INSTANCE NAME] | TCP/IP
Launch SQL Server Configuration Manager on your VPS.
Take a look at the SQL Server Network Configuration. Make sure that TCP/IP is enabled.
Next look at SQL Server Services. Make sure that SQL Server Browser is running.
Restart the service for your instance of SQL Server.
Open the SQL Server Configuration Manager....
2.Check wheather TCP and UDP are running or not....
3.If not running , Please enable them and also check the SQL Server Browser is running or not.If not running turn it on.....
Next you have to check which ports TCP and UDP is using. You have to open those ports from your windows firewall.....
5.Click here to see the steps to open a specific port in windows firewall....
Now SQL Server is ready to access over LAN.......
If you wan to access it remotely (over internet) , you have to do another job that is 'Port Forwarding'. You have open the ports TCP and UDP is using in SQL Server on your router. Now the configuration of routers are different. If you give me the details of your router (i. e name of the company and version ) , I can show you the steps how to forward a specific port.
I had the same issue where my firewall was configured properly, TCP/IP was enabled in SQL Server Configuration Manager but I still could not access my SQL database from outside the computer hosting it. I found the solution was SQL Server Browser was disabled by default in Services (and no option was available to enable it in SQL Server Configuration Manager).
I enabled it by Control Panel > Administrative Tools > Services then double click on SQL Server Browser. In the General tab set the startup type to Automatic using the drop down list. Then go back into SQL Server Configuration Manager and check that the SQL Server Browser is enabled. Hope this helps.
Disable the firewall and try to connect.
If that works, then enable the firewall and
Windows Defender Firewall -> Advanced Settings -> Inbound Rules(Right Click) -> New Rules -> Port -> Allow Port 1433 (Public and Private) -> Add
Do the same for Outbound Rules.
Then Try again.
I recently upgraded from SQL 2008 R2 to SQL 2012 and had a similar issue. The problem was the firewall, but more specifically the firewall rule for SQL SERVER. The custom rule was pointed to the prior version of SQL Server. Try this, open Windows Firewall>Advanced setting. Find the SQL Server Rule (it may have a custom name). Right-Click and go to properties, then Programs and Services Tab. If Programs-This program is selected, you should browse for the proper version of sqlserver.exe.
If you have more than one Instances... Then make sure the PORT Numbers of all Instances are Unique and no one's PORT Number is 1433 except Default One...
Open SQL Server Configuration Manager.
Click SQL Server Services, on the right side choose the server you've created during installation (by default its state is stopped), click once on it and a play button should appear on the toolbar. Click on this play button, wait til its state turns to "Running". Now you're good.
Open SQL Server Management Studio; switch the "Server Type" to "Database Engine" and "Authentication" to "SQL Server Authentication". The default login is "sa", and the password is the password that you chose on creating the server. Now you're good to work.
In my case the problem was caused by the inconsistency between computer names. In system settings my computer was named with some long name, but apparently the name used for some certain communications was trimmed.
I changed the name in the settings to a shorter one and it worked.
I had built both a console app and a UWP app and my console connected fine, but not my UWP. After hours of banging my head against the desk - if it's a intranet server hosting the SQL database you must enable "Private Networks (Client & Server)". It's under Package.appxmanifest and the Capabilities tab.Screenshot
Before download the last version and update your sql server to fix errors of TLS 1.2 on Sql Server 2012. For more information, check here.

cannot connect to local server

I have SQL Server 2005 installed in my local machine. When I installed it, I was able to connect to the local server which is named "MNTCON016".
After restarting the machine, I found out that i was not able to connect to the local server "MNTCON016":
A network related or instance specified error occured while
establishing a connection to SQLServer. 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: Named
Pipes Provider, error: 40- Could not open a connection to SQL
Server)(Microsoft SQL Server, Errorv 2)
After a lot of troubleshooting, I installed the same setup again and named the instance "MNTCON016\SQLEXPRESS", and then again it allowed me to connect properly.
But when I restart the machine, it gives me the same error as before. On the other hand, it allows me to connect to remote database servers on the network. The only problem is with my local server.
Try to open Start/Programs/Microsoft SQL Server 2005/Configuration Tools/SQL Server Configuration Manager.
Open node SQL Server Network Configuration and click Protocols for MSSQLSERVER. Verify which protocols are enabled. For example, I have named pipes disabled on my machine.
Also open SQL Native Client Configuration and click Client Protocols and check wchich protocols are enabled.
Regards
Piotr
Goto Run from start menu.
Type services.msc there. This gives you a list of all runnig services on your local machine.
Be sure that services for your SQL Server instance is running. These services should be set to automatic if you want them to start when windows starts.

Resources