SQLAnywhere .NET Connection String - sqlanywhere

I'm using SAP's SQLAnywhere 17 .NET library to connect to a database (in PowerShell), but can't find anything on the internet for the connection string format.
My credentials are as follows:
Host: 10.10.10.10:12345
Server: testserver
UID: DBA
Password: 123
Database: testdb
This string generated by SQL Central does not work; gives me "The user 'SQL Anywhere' does not exist."
UID=DBA;PWD=123;Server=testserver;dbn=testdb;ASTART=No;host=10.10.10.10:12345

You can create an ODBC data source on your machine first.
Then in your .Net code you can use ODBC Connection, the connection string will be something like this.
UID=DBA;PWD=123;Server=testserver;dbn=TestDSN;

Related

Error to connect Postgresql DB from Oracle dblink using Oracle Database Gateway

I'm trying to connect from Oracle Database (dblink) to Postgresql database use Oracle Database Gateway (dg4msql 19), on the Oracle Database Gateway for MS SQL Server all work fine. On the Oracle DB create dblink, but when try to connect get Error message:
ORA-28500 Oracle ODBC SQL Server Wire Protocol driver Socket closed
08S01 Oracle ODBC SQL Server Wire protocol driver
The server does not support SSL {HY000} !
listener work, tnsnames.ora also give correct answer. May be in initdg4msql.ora file I have to use some string to connect without SSL?
HS_FDS_CONNECT_INFO = postgre_servet.net:5432//database - I don`t known that is correct for PostgreSQL, or for PostgreSQL should use only ODBC connection?
How correctly use HS_FDS_CONNECT_INFO = postgre_servet.net:5432//database, or for PostgreSQL should I use only ODBC connection?
The PostgreSQL server is not configured to accept SSL connections.
First, verify that PostgreSQL was built with SSL support: that can be seen from the output of pg_config --configure (should contain --with-openssl).
To configure SSL support, set ssl = on in postgresql.conf and provide a server certificate and private key (parameters ssl_vert_file and ssl_key_file). Reload PostgreSQL to activate.
For details, read the documentation.

How can I call a postgresql db stored in DigitalOcean from ASP.NET Core web api?

I'm tying to use the connection string provided by DigitalOcean directly on the appsettings.json file, but shows error
ArgumentException: Keyword not supported: postgresql://XXXXX_user:xxxxxxxxxxxxx#db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com:xxxxx/trackbus?sslmode (Parameter 'keyword')
Npgsql.NpgsqlConnectionStringBuilder.GetProperty(string keyword)
This is the exact connection string provided by DigitalOcean:
postgresql://xxxx_user:xxxxx#db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com:xxxxx/TrackBus?sslmode=require
I'm using Npgsql nuget package, when the db was local was working fine using th regular connection string
"Server=xxx.0.0.x;Port=xxxx;Database=TrackBus;User Id=postgres;Password=xxxx;"
I've also tried this (private and public):
"Server=private-db-trackbus-nyc3-xxxxx-do-user-xxxxx-0.b.db.ondigitalocean.com;Port=xxxxx;Database=TrackBus;User Id=xxxxx_user;Password=xxxxxxxxxx;Integrated Security=true;"
Error:
An unhandled exception occurred while processing the request.
PostgresException: 28000: no pg_hba.conf entry for host "xxx.xxx.xxx.xxx", user "xxxx", database "TrackBus", SSL off
I searched this last 28000 exception but couldn't apply any solution found.
The connection string provided by DigitalOcean is for CLI:
postgresql://xxxx_user:xxxxx#db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com:xxxxx/TrackBus?sslmode=require
You have to convert it to the format that appsettings.json uses and it will be like this:
"Server=db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com;Port=xxxxx;Database=TrackBus;User Id=xxxxxxxx;Password=xxxxxxxxx;sslmode=Require;Trust Server Certificate=true;"
The sslmode=Require;Trust Server Certificate=true; is super important because the managed database in DigitalOcean has it that that one.
Also remember that all postgresql database by default are blocking remote connection, you have to add the permission on the pg_hba.conf file from the Postgresql installation folder.

Why do psycopg2 and pyodbc connect to databases differently? And how could I translate a connection?

So I've been trying to find a good module for querying information at my company's POSTGRES databases.
There are so many modules around, but I can only seem to get pyodbc to work.
Why is pyodbc's form of connecting different than psycopg2, which seems to be the superior module?
And how would I translate my connection query from one to the other?
I can connect to my company's server like this with **pyodbc** no problem.
pyodbc.connect("DRIVER={SQLServer};SERVER=some\servername;DATABASE=someDatabaseName;Trusted_Connection=yes")
But this doesn't work for psycopg2 with:
psycopg2.connect(database="someDatabaseName", host="some\servername")
psycopg2 returns:
OperationalError: could not translate host name "some\servername" to
address: Unknown host
Of topic:
I hope someone can help, my heroku server simply does not want to install pyodbc
pyodbc is a Python module that can be used to connect to many different types of databases using the ODBC API. Specifically, pyodbc is compliant with the DB API 2.0 spec.
Your working code sample uses an ODBC implementation of a SQL Server driver to connect to a SQL Server instance. Drivers are DBMS-specific, ODBC is not.
I had the same issue. I wanted to re-use the ODBC connection details as used by pyodbc to connect to a PostgreSQL DB using psycopg2.
The connection details can be found in the Windows registry.
Basically, the following code will extract the required details from the registry:
import os
from winreg import (
ConnectRegistry,
HKEY_LOCAL_MACHINE,
OpenKeyEx,
QueryValueEx,
)
def odbc_dsn_2_psyopg2dsn(odbc_dsn, user, pwd ):
"""
This function converts a windows ODBC DSN to a dsn
that can be used by psycopg2.
It reads connection parameters from the windows registry,
username and password are often not in there,
and can be supllied as parameters.
"""
# get hostname, port, sslmode from odbc registry
hreg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
key = f"SOFTWARE\\ODBC\\ODBC.INI\\{odbc_dsn}"
hkey = OpenKeyEx(hreg, key)
hostname = QueryValueEx(hkey, "Servername")[0]
portnumber = QueryValueEx(hkey, "Port")[0]
sslmode = QueryValueEx(hkey, "SSLmode")[0]
database = QueryValueEx(hkey, "Database")[0]
#set defaults for portnmumber and SSL mode (my pref, maybe in your case there are in the registry too)
if not portnumber:
portnumber = "5432"
if not sslmode:
sslmode = 'Prefer'
# using all of the above, create psycopg2 connection-dsn
return f"dbname={database} user={user} password={pwd} host={hostname} port={portnumber} sslmode={sslmode}"

Error - Create database connection in eclipse

I am having trouble when I try to create a database connection in eclipse.
I created a connection to Sql server 2008. Database name, host, port, username, password, driver: sqljdbc ... everything is true. I ping successfully.
But when I see my connection, it shows all my databases and the hibernate tool cant see any table in database.
You can see in this picture

SQLCODE=-104, SQLSTATE=42601, DRIVER=4.7.85

Any idea of how to connect to db2 in an sql file in an Eclipse application?
I spent hours on trying to connect db2 using the following statement without any luck
[CONNECT'jdbc:db2://localhost:50000/DB2ADMIN;create=true;user=db2admin;password=db2admin']
What I'm typing wrong?
I can ping the db and I can create tables but can not connect to it into my application
please help....
Are you sure about your connection string:
Server: localhost
Instance number: 50000
Database name: db2admin
Username: db2admin
Password: db2admin
It is weird to have a database called db2admin.
What is the purpose of the 'create' option in the URL. I did not found that in the documentaion.
For more information about how to define the URL, please take a look at this page: http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_rjvdsprp.html