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
Related
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.
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.
I'd like to know if the Plotly Database Connector (when doing a SQL Server connection) supports a SQL Server Express edition database.
I tried to connect using the sa username and its password but nothing happened. I get the error:
Failed to connect to [hostname]:[PortNumber] - connect ECONNREFUSED [my IP address]:[PortNumber]
These are my inputs:
Username: sa
Password: mypassword
Host: myHost (SQL Server Express as my instance)
Port: (I left this port blank)
Database: myDB
So, it is compatible? Or does it only work with (full) SQL Server?
Well I achieved to connect SQL SERVER Express with the Plotly Database Connector, so I hope this answer helps someone in the future!
First of all I asked in its GitHub page and the developer answered with a reference of the same problem and its solution.
Basically you have to search and modify the file named: connection-manager.js
Which was located in this directory: C:\Users\Arturo\AppData\Local\Programs\plotly-database-connector\resources\app\node_modules\sequelize\lib\dialects\mssql\connection-manager.js after I installed the Connector in my PC (your path may vary).
Then, you open it, and, in the line 42 you'll see this code (if it isn't in that line just look up for the code) :
var connectionConfig = {
userName: config.username,
password: config.password,
server: config.host,
options: {
port: config.port,
database: config.database
}
The problem here is that you have to give it the instance name, so, we will add one line more of code:
var connectionConfig = {
userName: config.username,
password: config.password,
server: config.host,
options: {
port: config.port,
database: config.database,
instanceName: 'SQLEXPRESS'//this line.
}
And that's it! We save the file and restart our Plotly Database Connector, after doing it we introduce our credentials as usual (without the \sqlexpress in the host field) and it will work!
Note: If you have a text editor like SublimeText, it's easier to find the code that I'm showing, just press Ctrl+Shift+F and search by folder, inserting the full path of the Plotly Database Connector.
I am trying to connect to a SQL server using Windows authentication. I am doing it through node js on Visual Studio.
The SQL server is on my machine itself.
It had worked fine for the connection string
var config = {
server: '10.2.9.208',
database: 'DFMProAnalyticsCopy',
user: 'sa',
password: 'admin123#',
port: 1433 //default port number
};
But this was only for SQL authentication.
Now for Windows aunthentication, I have this connection string
var config =
"Driver ={SQL Server};Server = 10.2.9.208;Database=DFMProAnalyticsCopy;Trusted_Connection=True;";
This gives me error
Unknown driver SQL Server!
and this connection string
var config =
"Server = 10.2.9.208;Database=DFMProAnalyticsCopy;Trusted_Connection=True;";
gives error
Login failed for user ''
It is trying to attempt SQL authentication when I want Windows authentication. I have Mixed mode authentication ON.
I read at many places but am still unclear about it.
"Login failed for user ''" when trying to use Windows Authentication
Please help me.
EDIT 1:
I cannot use the configuration string as in SQL Server connection with jQuery and node js
because mine is centralised and anyone could be using it, so I need to use Trusted_connection=true or Integrated security = SSPI. I dont have windows login credentials of people using the system.
This worked for me. I had to provide an UID and password in the connection string, else it considered a null string for UID
var config = "Server={IPV4 of server};Database=dbname;Uid=domain\\username;Pwd=pwd";
i must connect to a sql server with windows authentication
sql server is on machine 192.168.3.6
web server (client) is on my machine 192.168.3.10
I'm using JTDS driver
dbUrl=jdbc:jtds:sqlserver://192.168.3.6:1099/db_test;instance=test
Connection con = DriverManager.getConnection( dbUrl, "", "" );
I have username and password of administrator user of sql server !
I also put ntlmauth.dll into c:\windows and c:\windows\system32 and I have always error:
java.sql.SQLException: Login failed for user '(null)'. Reason: Not
associated with a trusted SQL Server connection.
Any idea to solve my problem ?
Thank you very much
See jTDS FAQ http://jtds.sourceforge.net/faq.html
you will have to pass useNTLMv2=true and domain=yourdomain
What you can do is something like:
String url = "jdbc:jtds:sqlserver://MYPC/MYDB;instance=SQLEXPRESS";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(url);
Make sure you have jtds.jar in the Java build path.
Also, add "-Djava.library.path="PATH\JTDS\x64\SSO" where 'Path' is where your SSO folder is after installing the JTDS driver (this is where you have your ntlmauth.dll).
Here is a short step-by-step guide showing how to connect to SQL Server using jTDS (as well as JDBC) with Windows authentication should you need more details. Hope it helps!