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?
Related
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
I'm trying to connect to microsoft sql server using 8.2 version of jar.
It works fine when I'm using the same username, password in DBeaver. I'm not using any additional options in the connection string of DBeaver. I'm using the type SQLServer Authentication. It gets connected in DBeaver but I'm not able to open a connection via Scala repl.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
val props=new java.util.Properties
props.put("user","")
props.put("password","")
// URL : jdbc:sqlserver://host:port // No additional options like in DBeaver
DriverManager.getConnection("url",props)
Error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'USERNAME'. ClientConnectionId:CONNECTIONID
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:283)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:129)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:37)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:5173)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3810)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:94)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3754)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7225)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3053)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2562)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2216)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2067)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1204)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:825)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
... 47 elided
I am trying to use python in a virtual environment to write a dataframe to sql server. I can read from the server with my pyodbc connection, but can't write to it using that connection, so I'm using a sqlalchemy engine, and credentials stored in a .env file.
Printing the raw string returns:
'mssql+pyodbc://User:Password#Server/Database?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'
but when printing the engine it returns:
'mssql+pyodbc://User:***sword#Server/Database?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'
If I try to connect using the engine, the login timeout expires, which I'm assuming is because the engine isn't passing the correct credentials.
Is there something going on with my string formatting?
import os
from sqlalchemy import create_engine
from dotenv import load_dotenv
load_dotenv()
credentials = [os.getenv('UID'), os.getenv('PWD'), os.getenv('Server'), os.getenv('Database')]
engine = create_engine('mssql+pyodbc://{0}:{1}#{2}/{3}?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'.format(*credentials),fast_executemany=True)
print('mssql+pyodbc://{0}:{1}#{2}/{3}?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'.format(*credentials))
print(engine)
engine.connect()
The __repr__ method for Engine purposely obfuscates the password, replacing it with ***:
import sqlalchemy as sa
connection_url = sa.engine.URL.create(
"mssql+pyodbc",
username="gord",
password="p#ssword",
host="192.168.0.199",
query={
"driver": "ODBC Driver 17 for SQL Server",
},
)
print(connection_url)
# mssql+pyodbc://gord:p%40ssword#192.168.0.199?driver=ODBC+Driver+17+for+SQL+Server
engine = sa.create_engine(connection_url)
print(engine)
# Engine(mssql+pyodbc://gord:***#192.168.0.199?driver=ODBC+Driver+17+for+SQL+Server)
Note that in this particular case the username and password arguments are irrelevant as Trusted_Connection=Yes is being used.
connection_url = sa.engine.URL.create(
"mssql+pyodbc",
host="192.168.0.199",
query={
"driver": "ODBC Driver 17 for SQL Server",
"Trusted_Connection": "Yes",
},
)
This is what you should do....
credentials = [username, password, server, database]
engine = create_engine('mssql+pyodbc://{0}:{1}#{2}/{3}?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'.format(*credentials),fast_executemany=True)
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?
I'm following this tutorial except that I do not wish to use Silex.
I have set up a Cloud SQL Second Generation instance and a local proxy, which I can successfully connect to using SQL Workbench. This is the code I'm using to connect with:
define('DBH_SOCKET', '/cloudsql/project-***:us-east1:instance-****');
define('DBH_NAME', 'testdb');
define('DBH_USER', 'root');
define('DBH_PASSWORD', '****');
$pdo = "mysql:unix_socket=".DBH_SOCKET.";dbname=".DBH_NAME.";charset=utf8";
try {
$db = new PDO($pdo, DBH_USER, DBH_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
echo '<br />';
if($db) echo 'YAY'; else echo 'NAY';
It works absolutely fine when I deploy the app an visit project-***.appspot.com, but the connection fails when I try to work locally.
Connection failed: SQLSTATE[HY000] [2002] No such file or directory.
I know this question has been asked before in various contexts, but none of their solutions are working for me or don't directly apply. I have added this to my app.yaml file with no change in results:
env_variables:
# Replace project, instance, database, user and password with the values obtained
# when configuring your Cloud SQL instance.
MYSQL_DSN: mysql:unix_socket=/cloudsql/project-****:us-east1:instance-****;dbname=testdb
MYSQL_USER: root
MYSQL_PASSWORD: '****'
beta_settings:
cloud_sql_instances: "project-****:us-east1:instance-****"
Why can't I connect locally using PDO when I can connect locally using my SQL client?