How to Expose SQL Server Hosted on Intranet to Connect Remotely - sql-server

I am trying to remote connect to a SQL Server that is hosted on a company intranet. Ultimately, I would like to connect in with something like tedious and get the data into a web application via a REST API.
I followed this tutorial: https://blogs.msdn.microsoft.com/friis/2016/08/25/setup-iis-with-url-rewrite-as-a-reverse-proxy-for-real-world-apps/
Entered the client_net_address:1433 for the inbound rule.
Disabled SSL Offloading
Entered the public facing IP of the server in the outbound To: field but changed the last digits. e.g. xxx.xxx.xxx.100
When I try logging in with tedious I get a connection timeout error using the following config:
let config = {
userName: "**",
password: "**",
server: "xxx.xxx.xxx.100",
options:{
port: 1433,
database: "db_name",
encrypt: true
}
}
What steps must I take to connect remotely to a SQL database hosted on an intranet?
Currently I VPN in and can query from SQL Server 2014 Management Studio.

This feature is working for node module mssql version 3.3.0 and SQL Server 2008.
Use npm install mssql#3.3.0 and connectivity should work properly.
Version 4 of the mssql module has breaking changes.

Related

How to connect a .NET API to a SQL Server database both in the same Kubernetes cluster?

I have a SQL Server running in a pod and an API running in another pod in the same cluster deployed with helm.
I'm able to connect to the database with a port forward and I created a user using Microsoft SQL Server Management Studio.
I point out that it's for a development environment and all is ok in production (production databases are outside the cluster).
When my API is deployed, this error is thrown in his pod :
An error occurred seeding the DB.
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
And
An error occurred using the connection to database 'dbdev' on server '127.0.0.1,1433'.
I wonder which connection strings to put in order to connect to the database because with that connections strings, it doesn't work :
"Server=tcp:127.0.0.1,1433;Initial Catalog=dbdev;Persist Security Info=False;User ID=xxxxxx;Password=xxxpasswordxxx;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True;Connection Timeout=30;"
If it's a problem of connection strings, isn't localhost point inside my cluster ? or am I out of step.
Ok i found out my problem, i dont have to put IP address in my connection strings but the name of the service in the cluster.
"Server=service-name-in-cluster,1433;Initial Catalog=dbdev;Persist Security Info=False;User ID=xxxxxx;Password=xxxpassxxxx;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True;Connection Timeout=30;"
This error message indicates that the .NET API is unable to establish a connection to the SQL Server database. There could be a few reasons why this is happening:
Incorrect server name or port: Make sure that the database host and
port specified in the API's configuration are correct. You can verify
this by checking the name and port used in the SQL Server Deployment
and Service.
Network connectivity: Ensure that the .NET API and SQL Server are in
the same network and can communicate with each other. You can use
kubectl exec to run a ping command from the API pod to the SQL Server
pod to test the connectivity.
Firewall rules: Make sure that the SQL Server port is open and
accessible from the .NET API. If you're using a firewall, you may
need to add a rule to allow traffic on the SQL Server port.
Incorrect credentials: Make sure that the credentials specified in
the API's configuration are correct and match the credentials used by
the SQL Server.
SQL Server instance not running: Check that the SQL Server instance
is running and accessible. You can do this by checking the status of
the SQL Server pod in the cluster and making sure that the SQL Server
service is running.
If the issue persists, you may need to inspect the logs of the API pod and the SQL Server pod to gather more information about the problem.

MS SQL Server dotnet core connection issues

I'm using ASPNetBoilerplate and attempting to deploy docker images of an ASP.NET MVC/Vue.js app. The app builds and runs fine on development environments with a trusted connection to a local SQL Server. When I try to deploy to docker running on Ubuntu 20 attempting to connect to SQL Server running on a Windows 2019 Server I am consistently getting
Login failed for user '[removed]'.
Reason: Password did not mach for the login provided. [Client xxx.yyy.zzz.aaa]
I can use those exact same credentials to connect to the database server using either Azure Data Studio or SQL Server Management Studio.
It turns out that dotnet core is a bit picky about how a SQL Server is called in the connection string. I had to include the port, even though it is the standard port.
Working Connection String:
Server=172.16.0.19,1433; Database=Db; User Id=Uid; Password=Pass;
Non-working Connecting String, throwing a Login error as listed in the question:
Server=172.16.0.19; Database=Db; User Id=Uid; Password=Pass;
To Use Docker with Asp.net Boiler Plate I try this connection string and it works fro me
{
"ConnectionStrings": {
"Default": "Server=10.0.75.1,1433; Database=MyProjectDb; User ID=sa;Password=PASSWORD';Trusted_Connection=False;MultipleActiveResultSets=True;"
},
Note : 10.0.75.1 is the default docker internal switch
Both Local & Staging is working
"ConnectionStrings": {
"Default": "Server=host.docker.internal,1433; Database=ms19Db;User=sa; Password=yourStrong(!)Password;"
},

express project not connecting to database (express)

At work I have been creating a full stack website using express and react with a sql server database.
I have now been self isolated due to the corona virus (everything at work was working fine).
I have restored the database and the code.
I have enabled tc/ip and pipelines in sql server configuration manager.
I have the made sure the password for the sa account is correct.
this is what i receive
] Err: ConnectionError: Connection is closed.
What else is there to check to make sure this is working?
Any help in what I may have overlooked would be great
edit ----
using npm mssql here is config
var config = {
user: "sa",
password: "Mypassword123",
server: "localhost", // You can use 'localhost\\instance' to connect to named instance
database: "CDA"
//enableArithAbort: false
};
I solved this by creating a default instance of sql and using this instead of the named instance I was trying to use.

Connect to database over internet

I'd like to connect to my MS SQL database hosted on another computer over internet.
What I did:
-> I'm using NO-IP (dynamic DNS)
-> I created SQL Authentication Account and I can connect to it from local computer using MSSMS like this:
Server name: local_ip\SQLEXPRESS Login: ###, Password: ###
-> I disabled firewall
-> I set port in SQL Server Configuration Manager (to 49XXX) and forwarded this port AND 1434 in router settings to my computer
-> SQL Server Browser is running
Now I'd like to connect to this DB from another computer (different network): Server name: tcp:my_no_ip_name.ddns.net,49XX Login: ###, Password: ###
I can't connect. All the time I get "Cannot connect to my_no_ip_name.ddns.net"
Am I missing something?
on local ssms, try to connect as yourserver.ddns.net,portnumber\instancename. windows authentication doesnt work on mine but ok with sql server authentication (try to avoid using sa account). dont forget to port forward on the router and open port in sql server firewall. Leave the ports on default (1433) in config manager. Not the most secure but once it works you can harden it by changing it to a non-default port and using a more secure user id in sql server logins which only has access to the database you want...

how to connect to SQL server that works on computer that uses proxy

My SQL server installed on remote computer, that works via proxy server. I know the external IP address, and local network IP of computer. How can I connect?
Follow instructions on MSDN:
Connecting to SQL Server Through a Proxy Server:
How to: Connect to SQL Server Through a Proxy Server (SQL Server Configuration Manager)
If the computer hosting SQL Server is behind a proxy server, and you have no alternate route to that host other than through that proxy server, you're going to have to determine the process necessary to configure the proxy to allow connections from your box to the SQL server...

Resources