Diagnose SSMS connection issue with Azure VM - sql-server

I created a virtual machine and install our own copy of MS SQL2016. I can connect fine from the VM but when I try to connect from outside (my office) it say that it cannot find the network instance. I have tried the Server name (Mapped in host file) the DNS name connected to the public IP and even the public IP. I have enabled the TCP/IP protocol and set the port (1433), set up a Windows firewall rule, set up incoming rule in Network security group, read articles and tried many things but still same message .

Anyone have an idea?

Related

Cannot connect to Azure VM with SQL Server

I cannot get my Azure VM with SQL Server to connect from anything other than the local machine. This is a Windows VM where I downloaded and installed SQL Server manually. I am at a loss.
If I RDP to the machine and connect to SQL Server it succeeds. If I attempt to hit it from any other box on my Virtual Network it will not connect. I can ping the box and the name resolves to the proper IP address. Test-NetConnection shows that I cannot connect on port 1433, but I can connect on other ports like 3389.
Here is all I've tried/confirmed thus far.
TCP/IP is enabled in configuration manager and set to listen on port 1433. Remote access is enabled in configurations.
I added a port 1433 Windows firewall rule for all 3 profiles.
I turned off the Windows firewall for all 3 profiles.
Confirmed both machines are definitely on the same virtual network.
The default NSG rule is in place for any port/protocol on the same Virtual Network.
I added an explicit NSG rule for the source IP of another machine to any port/protocol.
I modified the rule that allowed me to RDP to the box from my personal IP to include 1433 in addition to 3389. Test-NetConnection succeeds on 3389 and fails on 1433.
None of these made a difference.
I created a new VM where the machine came pre-installed with SQL Server. It connects just fine from any other machine on the VirtualNetwork without making any changes to any firewall or NSG rules.
What am I missing?
Is SQL listening on the internal address and an allowed connection IP? http://www.mohamedmostafa.co.uk/blog/2009/10/10/setup-configure-microsoft-sql-server-to-allow-remote-connection-remote-sql-management-studio-access/
Sound like your MSSQL is setup with a dynamic port in the tcp/ip protocol. Check the TCP/IP protocol and if the port is blank, set it to the desired port (1433) and set NSG to allow communication on this port.

Unable to telnet to SQL mirroring port on public IP on Azure ARM VM

I am trying to mirror a on premise SQL database to Azure ARM VMs running SQL server. One for the mirror and one for the witness. I have setup the mirroring end points on the servers. However, I am getting an error to the effect that the mirror server can not be reached.
Reading through the net pages, I tested the port using telnet. I am able to telnet to the mirroring port on my local server from the Azure VM but unable to telnet from the local server to the VMs.
I am able to telnet on the mirroring port between the VMs using the Private IP Address but unable to do so using the Public IP address.
I have added the port to the Security group being used by these VMs to allow inbound connections as well as outbound connections.
I have tested that the server is listening on ip 0.0.0.0 and my mirroring port.
Any help would be very much appreciated.
For whatever its worth, I was setting the Inbound connections source port range as the port I was going to use for mirroring. I changed this to "*" and it started working.

Unable to connect to SQL Server 2014 remotely

Unable to connect to SQL Server remotely
I have installed SQL Server 2014 Express on Windows 10. I can connect to server locally by entering: computername\SQLEXPRESS or 192.168.0.xxx\SQLEXPRESS
When I try to connect to the server using public ipadress
122.xxx.xxx.xxx\SQLSERVER
I get an error:
Error: 26 - Error Locating Server/Instance Specified) (.Net SqlClient
Data Provider)
I also have host name from dlinkddns, tried connecting with host name with same error.
Steps which I have tried:
Enabled remote connections.
Configured 1433 TCP port to be allowed in firewall. Disabled antivirus program. I tried disabling firewall with no success.
Enabled all protocols "TCP/IP', 'Named Pipes', 'Shared memory'
Under TCP/IP properties, changed 'IP All' 'TCP Port' to 1433. I tried enabling IP1 to public ipadress with port 1433 with no success.
I have dlink DIR 816 router, i dont see anything called port forwarding instead it has 'port triggering', i configured to allow port 1433 TCP and 1434 UDP.
I can ping both ipadress and hostname with success but the server would not connect.
I have tried everything to the best of my knowledge but nothing works, any inputs to setup my connection remotely will be of great help!
The error is pretty specific here.
error: 26 - Error Locating Server/Instance Specified (.Net SqlClient Data Provider)
You must understand one thing. Your local IP (192.168.0.xxx) is not visible from WWW. Only your Public IP or Global IP is. Once someone comes inside your network they will be able to ping your IP (192.168.0.xxx).
To make it work, you must have the SQL Server installed in a computer whose local IP is accessible from the internet. That means, it should be hosted in a Domain.
Connecting to SQL Server over the Internet
We can connect to SQL Server remotely over the internet if the Server has a static public IP address and port forwarding is configured on the router to allow remote connection requests through the router firewall.
In the router firewall settings, there is normally a games and application section, in there add SQL application and give the port range (1433 normally) and then direct the incoming connection by selecting the SQL Server device name on the network.
I fixed the issue by adding local ip into DMZ on my router. Everything works like a charm now.

Connecting to a 2014 SQLEXPRESS database on an externally hosted computer through TCP/IP

I am working on a system whereby I can update a small database from several locations. I wish to host the database on my home computer and allow connections to be made to the database from two other locations through tcp/ip.
I have done the following thus far:
Enabled TCP/IP for SQLEXPRESS
Allowed port 1433 tcp on my firewall
Allowed port 1434 udp on my firewall
Enabled SQLEXPRESS server to allow remote connections
I was hoping to be able to connect to the database by opening sql management studio on the other pcs and using the following format [ExternalIP]\SQLEXPRESS but as of yet I have been unable to do so. I have looked at what my external IP might be and i am getting two different values:
86.XX.X.XXX
66.XXX.XX.XX
Should I be using either of these values with this format to connect from the other sql management studios when everything has been correctly configured? Are there any steps that I am missing?
Named instances of SQL Server don't listen by default on port 1433, but instead on a random port determined at each service startup. It's the function of the sql browser service to provide clients with actual ports of each running instance (and that's done using the fixed 1434 udp port).
The necesary steps would be to configure the server to use a fixed port, then setup the firewall and router to allow that port. When connecting, just use the external IP address with the port but not the instance name (as that would invoke the browser service, which is unneeded with fixed ports).
To resume, necesary steps would be these:
Enable remote connections on the server.
Setup users and permissions as needed (Windows authentication is a pain over internet, so SQL authentication is strongly recommended)
Enable TCP/IP for the instance.
Configure the server to use a fixed port for connections (1433 being the standard). Look here for instructions.
Restart the database server.
Give permissions on the firewall to allow the server executable incoming connections on your selected port. At this point other computers in the LAN should connect.
On your router forward the port you opened to your local machine private IP (note that in Windows you must configure your computer to use a fixed local IP instead of DHCP).
Test with a client over internet or just using your external IP.
Note that for the connection from the remote client, as server name you must use 86.XX.X.113,1433 (the port number is separated with a comma, optional if it's 1433). Notice that there is NO instance name, even if you installed it as SQLEXPRESS or whatever. This is due having a fixed listening port (like the default instance by default). That eliminates the need of the browser service and udp 1434, and the pain of a dynamic port forwarding.
You should also check that your ISP most likely will give you a dynamic external IP, so clients might be reconfigured when that changes. Or you can use some dynamic DNS service.
Config MSSQL Express 2014 connect remoto PC or PHP, etc..
View Video Tutorial Easy Config Server to MSSQL Express:
https://www.youtube.com/watch?v=5UkHYNwUtCo
Code Test Cliente Remote PHP:
$serverName = '192.168.1.64,49170'; //only the server name and ip MSSQL SERVER EXPRESS
$connectionInfo = array( "Database"=>"mydbName", "UID"=>"myUserId", "PWD"=>"myPass");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established";
}else{
echo "Connection could not be established.";
die( print_r( sqlsrv_errors(), true));
}

Connecting SQL Server Virtual Machine to Web Role in same Azure Virtual Network

I'm attempting to set up a Virtual Network in Windows Azure and use it to avoid opening a public endpoint on my (CUSTOM) SQL Server Virtual Machine. However, I continuously get a network related error, stating that the SQL Server wouldn't talk back in time, when trying to access my web application via my cloud service's URL.
I've looked all over the net for tutorials that show how to connect to one's own Custom-created VM instead of one of Windows Azure's preconfigured Virtual Machines, and found little of use. All the suggestions I've found I've tried.
I am working in Windows 7, using Visual Studio 2010 with the Windows Azure SDK installed, SP1.
Here are some details of what I have attempted to do to no avail.
I have:
created the Virtual Network with
its own Affinity Group
a single Subnet
added the Virtual Machine to it
making sure to put it in the same affinity group as the one I created for the VNet
installed SQL Server
configured SQL Server as per this tutorial
Added my databases and a login that I have verified can access the database
Both:
Converted an existing Asp.NET Website to a Web App and added a Azure Deployment Package thing see here for the tutorial I followed
I used r-click->Publish to Azure/Publish for this one, configured to use an existing Cloud Service I had already deployed in the VNet with the SQL VM, and made sure it was in the same Subnet as the VM.
it is also worth noting that this application did connect to a similar VM that was deployed outside the Virtual Network (still in Azure) by opening a public endpoint on port 1433 and using the Public IP address to connect to it.
Used the converted Web App's code in a brand new Azure Cloud Service project configured as per this tutorial (the first one I mentioned)
I attempted both publishing by:
r-click->Publish to Azure/Publish
r-click->Package and uploading it on the Azure Portal
in both cases both to
an existing Cloud Service in the VNet (and Subnet)
and a brand new Cloud Service created in the VNet (and Subnet) and upload package during creation or immediately publish to service as soon as started.
Double checked that all Cloud Services and Virtual Machines I've gone through were in the VNet, and in the same Subnet.
My Cloud service is usually at internal IP 10.4.2.5, and the VM at 10.4.2.4. My connection string is the same as the first tutorial I mentioned only with the proper authentication and my VM's internal IP specified. Connection string follows:
<add name="SQLServerinWAConnection"
connectionString="Data Source=tcp:SQLVMInternalIPAddress;Initial Catalog=MyTableName;User ID=loginName;Password=thepassword;Encrypt=true;Trusted_Connection=false;TrustServerCertificate=true"
providerName="System.Data.SqlClient" />
I also tried specifying Trusted_Connection=true
No matter what I try, I cannot get this application to connect to the SQL Server instance on that VM. I have even added a public endpoint to the VM at port 1433 and tried using its public IP and private IP, to no avail. That was my fallback, so now I'm at a serious loss.
Some implementation details that may or may not have any bearing:
The SQL Server instance is named, not default, so instead of just 'SQLServerVM' in the object explorer in SQL Server Management Studio, it has 'SQLServerVM\SQLServerDB'.
I have the port 1433 opened on the firewall on the VM for any IP range and any user
I will add any additional details (in case you don't want to read the whole tutorials to figure out what I've done) upon request.
There isn't by any chance a checklist available to state the things which need to be done for a web role or website to be able to connect to a virtual machine in its virtual network? That would greatly simplify troubleshooting.
Any suggestions would be greatly appreciated. I would very much like to have this working by the end of the day.
In my case, since our client installed SQL Server on the VM, using a named database instance, the service which hosted the instance I needed to connect to didn't have its TCP port set properly. So my detail that the SQL Server instance was named was indeed important.
If you just cannot figure out why your Web Role (Cloud Service) just isn't connecting to your Virtual Machine in the same Virtual Network, In addition to checking all of the things above in the question, check the following setting:
Log into the Virtual Machine (RDP)
Open the SQL Server Configuration Manager
Expand "SQL Server Network Configuration" in the left panel.
Click on "Protocols for {SQL Instance name here}" in the left panel.
Right-Click on "TCP/IP" in the right panel, go to "Properties..."
Double check that "Enabled" is set to "Yes".
Switch to the "IP Addresses" tab.
At this point, you should see that the "TCP Port" should be 1433 for at least the domain IP (in my case 10.4.2.4 in the "IP2" section), if not "IPALL" or some others.
Note that the "TCP Port" settings on all the "IP{X}" sections may have different values.
IF you don't see this SQL Server instance listening on 1433 (or some other port you are trying to configure):
Go to "IPALL" and change the "TCP Port" to 1433 (or whatever port you like, 1433 is the default that things will send to).
This will allow that port to be listened on for addresses coming to this server from anywhere.
Note that there is probably a cleaner way to do this, but this worked quite well for us.
This allowed me to access the SQL Server instance from all the Cloud Services in that VNet, using only the Internal IP Address of the VM, without a public endpoint opened for the port I configured (1433).
Just in case, here is the working connection string:
<add name="ApplicationServices"
connectionString="Data Source=tcp:{VM Internal IP}\{InstanceName},{port};Initial Catalog={Table};User ID={username};Password={passwd};Encrypt=true;Trusted_Connection=false;TrustServerCertificate=true" providerName="System.Data.SqlClient"/>
Make sure you replace:
{VM Internal IP} with your internal IP address
{InstanceName} with your SQL Server Instance's name, or leave it and the preceding \ out entirely if you have a default instance.
{port} should either be 1433 or whatever port you set open in your VM for that Sql Server instance.
{Table} with the Database table you want to use by default
{username} and {passwd} with those for your SQL Server user. Note that I am using SQL Server authentication here.
It's also worth noting that this did not open my server up to the internet (as expected), as I still can't get at it from the outside world, so it remains secured within the VNet this way.
Hopefully this will help someone in the future.

Resources