Knex cannot connect to LocalDB instance using named pipe - sql-server

I'm attempting to connect to a LocalDB instance through Knex using a named pipe:
np:\\.\pipe\LOCALDB#DBFBFA07\tsql\query
I can connect to it perfectly fine through SSMS & sqlcmd, but whenever I set my Knex config.server property to the named pipe, it says Failed to connect to: np:\\...\query - getaddrinfo ENOTFOUND np:\\...\query
The dev config that I'm using:
development: {
client: "mssql",
connection: {
database: process.env.SQLSERVER_DB,
user: process.env.SQLSERVER_USER,
password: process.env.SQLSERVER_PASSWORD,
server: process.env.SQLSERVER_SERVER
}
}
and my .env config:
SQLSERVER_DB=<db_name>
SQLSERVER_USER=<username>
SQLSERVER_PASSWORD=<password>
SQLSERVER_SERVER="np:\\.\pipe\LOCALDB#DBFBFA07\tsql\query"

The underlying mssql driver and TDS protocol implementation does not support named pipe connections to LocalDB. See this

Related

Docker in WSL - Can't connect to SQL server on 'localhost' but with '127.0.0.1' SQL Server 2017-latest

Trying to spin up an mssql server with a docker-compose file:
version: "3.7"
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2017-latest
container_name: sqlserver
user: root
ports:
- "1433:1433"
environment:
SA_USERNAME: sa
SA_PASSWORD: Dev1234!
ACCEPT_EULA: Y
MSSQL_AGENT_ENABLED: 'true'
volumes:
- ./volumes/data2:/var/opt/mssql/data
- ./volumes/backup:/var/opt/mssql/Backup
The server is up and running successfully, But when tried to connect with powershell script code:
$connectionString = "Data Source=localhost,1433;User ID=sa;Password=Dev1234!;"
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
$connection.Open();
It throws error like:
"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 - The
remote computer refused the network connection.)"
That is, it fails when trying to connect with 'localhost' as host, it is successfully connecting when "127.0.0.1" is specified as host.
The same happens when I tried to connect with SQL server management studio.
My docker engine is running in wsl, an ubuntu distro specifically. There is MySQL and different other servers already spun up which I can access with localhost.
Is there anything I need to specify in docker-compose to make this work? When checking documentation, there are no params aligned to it as I see.

NodeJS OracleDB connection string

I am running Oracle XE 21c in a Docker container and I can connect to it with a JDBC thin connection using the JDBC url jdbc:oracle:thin:#localhost:1521:XE using the SYSTEM account. I can also log into the terminal Docker instance and connect to the database fine.
When I try to connect to it using NodeJS OracleDB example code described here:
https://node-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html, I cannot get the client to connect using either:
connection = await oracledb.getConnection({
user : "hr",
password : mypw
connectString : "localhost/XEPDB1"
});
or
connection = await oracledb.getConnection({
user : "SYSTEM",
password : "MyPassword",
connectString : "localhost/XE"
});
I get an error ORA-01017: invalid username/password; logon denied.
I can connect to Oracle XE using sqlplus either by logging into the Docker container or from the host Mac using:
sqlplus SYSTEM/Password#localhost:1521/XE
if I change the nodejs code to:
const connection = await oracledb.getConnection({
//user: "SYSTEM",
//password: "Password42",
//connectString: connectionURI.url
connectString: "SYSTEM/Password#localhost:1521/XE"
});
I get the error:
ORA-12154: TNS:could not resolve the connect identifier specified
Any ideas why I can connect with sqlplus but not NodeJS OracleDB?

How to fix error: "Could not open a connection to SQL Server: Could not open a connection to SQL Server"?

I'm trying to connect to a Microsoft SQL Server docker container and migrate the database from the code.
But I get the following error:
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: 40 - Could not open a connection to SQL Server: Could not open a connection to SQL Server)'
My connection string:
"CatalogDbConnectionString": "Server=tcp:127.0.0.1,1433;Initial Catalog=CatalogDb;User Id=sa;Password=Passw#rd"
docker-compose.override.yml:
catalogdb:
environment:
- SA_PASSWORD=Passw#rd
- ACCEPT_EULA=Y
ports:
- "1433:1433"
volumes:
- /var/opt/mssql
Program:
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<CatalogDBContext>();
var env = scope.ServiceProvider.GetRequiredService<IWebHostEnvironment>();
var settings = scope.ServiceProvider.GetRequiredService<IOptions<CatalogSettings>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<CatalogDBSeedData>>();
context.Database.Migrate();
new CatalogDBSeedData().SeedAsync(context, env, settings, logger).Wait();
}

Failed to connect to local SQL Server using node

I am trying to connect to a local SQL Server database using the following config:
var config = {
server: "localhost",
port:1433,
user: 'sa',
password: 'sa',
database: 'newarbete',
options: {
trustedconnection:true,
}
}
but I failed. I get this error
Failed to connect to localhost:1433 - Could not connect (sequence)
I can connect to the same db when it is on the server (changing the config parameters of course).
What is wrong with the config parameters for the local database, or what I should do to make work here?

Config entry in node.js in case if of windows authentication to connect to SQL Server

How to create config entry in Node.Js to connect to SQL Server in the case of Windows Authentication using only mssql module?
I'm using this approach:
exports.dbConfig = {
server: "AKASH",
database: "SampleDB",
port: 1433,
options: {
trustedConnection: true
}
};

Resources