Connecting to a local SQL server from a website - sql-server-2008

We have a small network behind a firewall (WatchGuard XTM 2 series) and network switch. On our network we have multiple instances of SQL server, but 1 in specific that I would like to be able to access remotely from our website. We have a static IP address from our ISP and then all the machines on the network have a locally assigned dynamic IP address. When trying to connect to the database from outside our network how do I get the request to be directed to the proper machine / SQL instance? Is it a parameter in my connection string or something in my firewall?
A few things to rule out:
1) The firewall is allowing access from the website to our network. I added the site's IP and opened up port 1433. Also, when trying to connect and monitoring the firewall no exceptions come up as they did before I added the proper IP address.
2) Remote connections on the SQL server has been setup and enabled. I've done a lot of reading up on remote connections and I am sure it has been setup properly.
I am currently getting this error message on my site:
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.)

The Server parameter of the ConnectionString indicates what server to connect to. Assign an ip address or URL to the server that you want to access and put that in your connection string.

Related

SQLException when deploying ASP.NET Boilerplate application to Azure

I've been trying to deploy an ASP.NET Boilerplate application to Azure for the last couple of days and I haven't been able to do so. I keep stumbling upon this error:
First I make a Web App + SQL resource and then publish my project to it from inside Visual Studio using the right click -> deploy option, and then importing the publication profile I got from Azure. I make sure the database connection string in the appsettings.production.json are correct but I can't seem to connect to the database. If I try to connect to the database through the SQL Server Management Studio I get a similar error. This means something is wrong with the database itself.
Do I need to create a separate SQL database in Azure that makes use of the SQL database server that comes with the Web App + MySQL resource?
Any help would be greatly appreciated! I have been spending way too much time on this problem already.
This is a screenshot of all the resources in the Azure portal, these were created while creating the Web app + MySQL resource:
Edit: This is the error I am getting:
Win32Exception: 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. Unknown location SqlException: 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.) Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e) InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseSqlServer' call. Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute<TState, TResult>(TState state, Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>> verifySucceeded) Win32Exception: 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.
Since you mentioned you can't access db in any other way, I provided step-by-step instruction
You can get your connection string from Azure resource panel
Navigate to Connection security tab and enable access from other Azure resources. This way WebApp will be able access database server inside Azure network. I also added my client IP to test db connection from my PC later. Click Save at the top when you are done
On the same page there is setting called configure SSL connection. Certificate can be downloaded from https://learn.microsoft.com/uk-ua/azure/mysql/howto-configure-ssl. I used this file https://www.digicert.com/CACerts/BaltimoreCyberTrustRoot.crt.pem . Optionally, you could disable this feature for now.
Now we have everything to test db connection. I will show it with the use of HeidiSQL client.
Click open and see your databases
According to this you need to have CACertificateFile parameter appended to connection string to use SSL, so you need to put file into repository and provide its relative path in connection string
This was all caused by a stupid mistake, in the Azure portal I selected the Web App + MySQL resource instead of the Web App + SQL resource. For the ASP.NET Boilerplate project I am using you need a Web App + SQL resource.

I am unable to connect with my online phpmyadmin mysql database which i created for testing my windows forms application

error message from microsoft sql server management studioI set up a free phpmyadmin mysql database (online) and would like to use it for testing purposes on my windows forms application. I've been trying to connect to it from Microsoft server management studio and from visual studio but it always gives me the following error:
title: Connect to Server
Cannot connect to xxx.xx.xxx.xx(purposely ex'd out)
ADDITIONAL INFORMATION:
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476
The network path was not found
BUTTONS:
OK
------------------------------[connection error message][1]
If anyone can give me detailed steps on how to resolve this, I'll really appreciate.
welcome to Stack Overflow.
phpMyAdmin is a graphical interface for administrators to manage a MySQL or MariaDB installation. It's not an API that your Windows Forms application can access. You'll have to connect directly to the database (over the standard port 3306) or use some sort of API that's hosted alongside the database.
Most hosting providers block incoming connections on 3306, certainly I would expect a free MySQL hosting provider to do that as well. You'll have to ask the hosting provider if you're able to connect from your local machine to the database machine; you may need to add your IP address to a list of allowed hosts, for instance. Often, it's a bad idea to expose your MySQL installation directly to the internet (for security and performance reasons).
Your error message mentions named pipes. Named pipes are a Windows method for inter-process communication that is usually meant to be accessed from the same local machine (I believe Windows technically allows using a named pipe through a local network connection, but you're certainly not on the same local network segment and your chances of the free hosting provider allowing you a way to access a named pipe from across the network are less than them opening up MySQL's port 3306). Somehow you'll have to adjust your connection string to connect via IP address or host name instead of named pipe.
And finally, your error message refers to SQL Server. Microsoft SQL Server is a very different database product from MySQL/MariaDB. If your code is expecting to connect to SQL Server, you won't be able to use a MySQL or MariaDB backend instead. The two products are different enough and even use different ports, so the code won't be able to connect.

Connecting MySQL Workbench with Google Cloud SQL

I have read and tried prior suggestions.
Here is what I have done.
I signed up for a static IP through a Proxy Server (that uses Port 3128)
I have tested that static IP is working (verified with several IP look up services)
I have chanced the authorized root password
I have tried setting the client host to Proxy Server value on the authorized users.
I have white labeled/authorized the static IP in Cloud SQL
I have tried both the IPv6 and IPv4 addresses from Cloud SQL in MySQL Workbench
I never get passed the error: Lost connection to MySQL server at 'reading initial communication packet', system error: 22 when using the IPv6 and Lost connection to MySQL server at 'reading initial communication packet', system error: 0 when using the IPv4
As an aside, I was able to authorize Zapier IP and have tested a webhook to Cloud SQL
It isn't clear from your description: did you whitelist your computer's IP address? There are sites that will tell you which IP address your computer is using, and that is the address you should use under the Access Control panel.

Connect SQL Server 2008 r2 through Internet

I have a VB.NET application that can connect to the SQL Server through LAN base, but how can I connect to it through internet, the application need to use outside, I know i need to use the public IP instead of using the IP address of the server but my public IP address that I've set in connection string can't connect to the server, Here's my connection string
Dim connstr$ = "Server=xxx.xx.xx.xxx\SQLEXPRESS,xxxx;Initial Catalog=sample_db;Integrated Security=True
Public conn As New SqlConnection(connstr)
I've try also to set the port and change the firewall restriction,enabled the TCP etc. and search a lot here but still doesn't work
Here's our network setup
PC-->router-->internet modem
1433 is the default sql server communication port. Port 1433 should be forwarded to the local IP address where your sql server runs.
1) Make sure that port 1433 is the valid communication port for sql server. You can check it from sql server configuration tools. Use actual port number rather than 1443 if it was changed by someone.
2) Find NAT (Network address translation) menu in your modem or router administration panel.
3) Forward port 1433 to your server's local IP address
4) Restart device
As a note that, your modem does not require a static IP. Your device most probably might have a new IP address after every restart. But it would be valid until you restart it once more. You can use this IP address in order to access your database remotely. It would be better but you don't have to get a static IP address.
UPDATE: You should also be sure that, port is not blocked by a program on the server such as a virus or security program.
Good luck
Google "port forwarding", which is also called Network address translation or "NAT".
The other answers are perfect but searching for the term on google should get you an idea on what it is, and how to go about it. Add your router name to the search for exact steps.
In short forward the port that SQL Server is listening on, from the router to the server machine. You will need to do some configuration on the router for that by opening the admin page. For how and details, Google "port forwarding"

SQL Server 2008 Remote Access

I've studied other topics, tried various solutions, but cannot gain access to my SQL Server remotely from my PC.
I have not problems with accessing the Server its running on, I'm able to Remote Desktop fine.
Here are the steps I have taken :-
Enabled Remote access to SQL Server
Created a SQL Authentication User Account (which Ii can log in with whilst on the server).
Enabled Shared Memory & TCP/IP Protocols for the SQL Server Instance.
Created a Firewall Rule for TCP Port 1433
Created a Firewall Rule for UDP Port 1434
Created a Firewall Rule for SQLBrowwer.exe
Created a Firewall Rule for SQLservr.exe
Ensured SQL Browser & SQL Server are running processes.
SQL Management Studio cant even detect the instance of the SQL Server in listed Database Engines.
I'm at a loss as to what the problem could be?
** UPDATE **
Ive tried turning off my Firewall, the SQL Server in now found in SSMS, but i still cant connect to it?
All your steps are right, I'd do the same. I'm sure everything is fine with your SQL Server.
I guess it's firewall, try to turn it off or run this from command prompt:
netsh firewall set portopening protocol = TCP port = 1433 name = SQLPort mode = ENABLE scope = SUBNET profile = CURRENT
Also, check if you have antivirus software or something similar and turn it off (on both sides).