express project not connecting to database (express) - sql-server

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.

Related

why does 'Django mssql connection error' happen?

i have an ready database and I wanna use it in django web project. but I have an error about connection.
here is the error
raise NotSupportedError('SQL Server v%d is not supported.' % ver) django.db.utils.NotSupportedError: SQL Server v16 is not supported.
here is the packeges
asgiref 3.5.2
Django 2.1.15
django-mssql-backend 2.8.1
django-pyodbc-azure 2.1.0.0
django-pyodbc-azure-2019 2.1.0.0
mssql-django 1.2
pip 22.0.4
pyodbc 4.0.35
pytz 2022.7
setuptools 58.1.0
sqlparse 0.4.3
tzdata 2022.6
and database settings
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME':'veritabanıProje2',
'USER': 'sa',
'PASSWORD':'**',
'HOST':'DESKTOP-MDLFE99',
'PORT':'',
'OPTIONS':{
'driver':'ODBC Driver 17 for SQL Server',
},
},
}
I'm using SQL server 2022.
also the db file's name DB.sql in project directory. but I write here the name that is written while I create database. (I tried with DB.sql also of course)
I can understand the fault is about version but which one is wrong I dont know.
It may be due to several reasons such as-
Incorrect database connection settings: Make sure that you have entered the correct database name, server name, and login credentials in your Django settings.
Network issues: If your Django application is unable to connect to the database server, it could be due to network issues such as a firewall blocking access or a network configuration problem.
Incorrect version of Django or Python: Make sure that you are using a version of Django and Python that is compatible with the version of the Microsoft SQL Server database you are trying to connect to
I will update if i can get more source

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;"
},

Nodejs connection with mssql showing error

I am trying to connect with my sql server using nodejs, with the following code.
const sql = require('mssql');
var config = {
user: 'user',
password: 'psw',
server: 'localhost',
database: 'sumit'
};
var mssql = new sql.ConnectionPool(config);
mssql.connect().then(function(){
var req = new sqlDb.Request(conn);
req.query("SELECT * from Category").then(function(res){
console.table(res);
});
}).catch(function(err){
console.log(err);
})
but everytime it is showing
ConnectionError: Failed to connect to localhost:1433 - Could not
connect (sequence)
how should i connect with my sql server?
i have tried to change config also
var config = {
user: 'user',
password: 'psw',
server: 'DESKTOP-VVN4PRG\\SQLEXPRESS',
database: 'sumit'
};
but still getting same error.
I resolved my problem. I am putting my answer here, So maybe it will help someone.
Step 1: Check if you have selected SQL Server and Windows Authentication mode on Server Authentication section
Path: SMSS>Go to object explorer properties> Security(Check SQL
Server and Windows Authentication mode, if not, then check it)
Step 2: Check if you have TCP Port 1433 and TCP Dynamic Port is Blank(not 0)
Path: SQL Server Configuration Manager>SQL Server Network Configuration>Protocols for SQLEXPRESS> Double click on TCP/IP>IP
Addressess> Check for IPALL and for 127.0.0.1
Step 3: If you have performed any of the above or both the operation then please restart all your SQL Services by going
Path: Window + R> type services.msc and hit enter> Check for your SQL Services and restart all
Hope this would help someone.
I struggled for more than 2 hours and finally landed on this solution to enable SQLBrowser and it worked like magic
In my case I had to do both things mentioned on the 2 answers above. I had to fix the IPALL on step 2 for answer 1.
And turn on the Sql Server Browser service too. Without this service the mssql would not connect.
This makes sense to me after read what this service does. Found this Microsoft article How SQL Server Browser works

How to Expose SQL Server Hosted on Intranet to Connect Remotely

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.

Connecting to SQL from Bamboo still throws error Login failed for user

I am attempting to connect my Bamboo instance to SQL Server, but I am unable to do so because of the error Login failed for user 'Bamboo'. Investigation into the log files shown in the location
C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\ERRORLOG
throws an error that I should not be getting at this stage of my attempted login. Server is configured for Windows authentication only. Currently able to login using same SQL Server credentials to access the database, just not via Bamboo.
The reason why this should not happen is because my server is already set up to do so, and I will list all of the steps that I have taken to prevent this error. In my localhost SQLEXPRESS server I have checked SQL Server and Windows Authentication mode. Once I restarted SQL Server, this worked as I was able to log in with the credentials that I added to a user called Bamboo.
The user I added is mapped to the database called BambooDatabase as a db_owner. The number of concurrent users is unlimited and I have tried disconnecting from SQL Server just to check if that was a problem, but still no difference. I added 2 more users with connect access and mapped to BambooDatabase.
I have went to the SQL Sever Configuration Manager and enabled TCP/IP and made sure that the IP addresses was pointing to 1433. And then configured my firewall to all access to 1433 as well. The fact that my error logs for SQL Server are appearing makes this seem that everything should be fine here. So with tested 3 users on SQL credentials everyone logged in successfully and all have the relevant permissions needed. All three gave the same error when trying to connect from Bamboo.
I am trying to connect to Bamboo like this:
Direct JDBC connection.
Driver class name: net.source.jtds.jdbc.Driver
Database URL: jdbc:jtds:sqlserver://localhost:1433;DatabaseName=BambooDatabase
User name: Bamboo
Password: SQL Server password
Checked overwrite existing data
Then once I click continue the log in error throws. Have I missed something here, I cannot see what I could do differently, I have tried to connect to SQL Server from Bamboo several different ways but have had no success. I am using SQL Server Express and the Bamboo version 5.11.3, I am testing upgrading from 5.11.3 to 5.15 with larges amounts of data which is why I am using that version.
Error from Bamboo is:
Error accessing database: java.sql.SQLException: Login failed for user 'Bamboo'.
Error from SQL logs is:
Login failed for user 'Bamboo' Reason: An attempt to login using SQL authentication failed. Server is configured for Windows authentication only. [CLIENT: 127.0.0.1]
Are you running Bamboo en SQLExpress on the same machine? If not, you should look into the remote access configuration.
In the SQL Sever Configuration Manager, make sure that you entered 1433 for the IPAll entry as well. And start the SQL Browser service for good measure, this is especially important when using a names instance, but going after the errorlog folder you copy/pasted, that's not the case.
For testing purposes, you might want to disable the firewall all together and reactivate is after you get the connection up.
Another thing to try if you're connecting on the same machine, is use the loopback address 127.0.0.1 instead of the localhost alias.

Resources