How to connect to Db2 from .NET 7 - c#

I'll need to connect to a Db2 server with C#.
On Nuget I've found IBM.Data.DB2.Core V3.1.0.600.
This package seems to be what I'm looking for but I don't get it work. Whenever I try to open the connection I'm getting an error.
DB2ConnectionStringBuilder sb = new DB2ConnectionStringBuilder
{
UserID = "MK1",
Password = "XXXX",
Server = "rei5",
Database = "testrei5"
};
DB2Connection connection = new DB2Connection(sb.ConnectionString);
connection.Open();
The error message is:
IBM.Data.DB2.Core.DB2Exception (0x80004005): ERROR [08001]
[IBM] SQL30081N A communication error has been detected.
Communication protocol being used: "TCP/IP".
Communication API being used: "SOCKETS".
Location where the error was detected: "172.17.1.50".
Communication function detecting the error: "connect".
Protocol specific error code(s): "10061", "*", "*". SQLSTATE=08001
According to the official docs, I've run these commands in the bin folder from nuget.
db2cli writecfg add -database BLUDB -host hostname -port 50000
db2cli writecfg add -dsn alias -database BLUDB -host hostname -port 50000
I've set alias to testrei5 and hostname to rei5. This worked after I've renamed the db2dsdriver.cfg.sample file in the cfg directory to db2dsdriver.cfg.
However, my connection still doesn't open.
Am I missing something here?

Related

Why the Instance of OracleConnection.Open() throws an error after upgrading the Oracle DB from 11g to 19c?

Connection String : USER ID=dt;DATA SOURCE=ABCTOOLQ;STATEMENT CACHE SIZE=10;PASSWORD=***;VALIDATE CONNECTION=True;DECR POOL SIZE=1;MIN POOL SIZE=1;INCR POOL SIZE=1
I am using Oracle.ManagedDataAccess from Nuget and System.Data.OracleClient in project reference.
m-connection.open() - Throws an exception
exception : {"ORA-01034: ORACLE not available\nORA-27101: shared memory realm does not exist\nLinux-x86_64 Error: 2: No such file or directory\nAdditional information: 3701\nAdditional information: -749403217"}
Property of m_connection :
The .ServerVersion create below exception :
Most likely is an Oracle Home issue. DATASOURCE=ABCTOOLQ will go looking in the tnsnames.ora for a reference, eg
ABCTOOLQ=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = yourhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yourservice)
)
)
If that tnsnames.ora cannot be found because
it was not copied to new client location (if you upgrade the client as well), or
the TNS_ADMIN environment or registry setting has been altered, or
the name of the service was altered during upgrade
then you end trying to connect to a local (and non-existent) database called "ABCTOOLQ", and thus the "Hey, that database is not there" error.

C# Keyword not supportet - CertificateFile - MySqlConnection

I am trying to establish a SSL connection to a MySQL Server.
Now I get the following error, when trying to connect:
Unhandled Exception:
System.ArgumentException: Keyword not supported.
Parameter name: CertificateFile
here is my Connection String:
MySqlConnection connection = new MySqlConnection(
"database=database;user=sslclient;" +
"CertificateFile=C:\\Users\\LSP\\documents\\visual studio 2017\\Projects\\App1\\App1\\client.pfx;" +
"CertificatePassword=XXX;" +
"SSL Mode=Required");
Do you know what the fault is ? As mentioned in
https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-ssl.html
it is valid.
I also tried to manage this with a MySqlConnectionStringBuilder, but this also dont work:
enter image description here
I am using the newest Version of MySql.Data from the NuGet Manager.
Thank you for you help,
Louis

Connect to SQL Anywhere - dblgen12.dll not found

I try to connect to a SQL Anywhere 12 database with the iAnywhere.Data.SQLAnywhere.v4.0.dll.
On the database server this connection is successful, however on any other PC's I get the error Language Ressourcefile not found<dblgde12.dll, dblgen12.dll>.
Orginal (german) error message here, unfortunately even on my english system the error message is in german.
I have found these files on the installation directory of the sql server, but I don't know what to do with them, since I can't install them in the gac.
The Connection:
iAnywhere.Data.SQLAnywhere.SAConnection connection = new SAConnection();
connection.ConnectionString = new SAConnectionStringBuilder(){ DatabaseName = "123", UserID = "123", Password =
"123", ServerName = "123" , Host = "10.11.11.10"}.ConnectionString;
connection.Open();
Thanks
After some more time asking google I found the following question asked:
http://sqlanywhere-forum.sap.com/questions/19449/cannot-find-the-language-resource-file-dblgen12dll
The accepted answer links to http://dcx.sybase.com/index.html#1201/en/dbadmin/da-install-s-5107108.html, where is explained where the dll looks for the files.
On Windows, SQL Anywhere searches the following paths relative to each
location in the preceding list:
.
..
.\bin32 and ..\bin32 (32-bit programs only)
.\bin64 and ..\bin64 (64-bit programs only)
.\java (for Java-related files)
..\java (for Java-related files)
.\scripts (for SQL script files)
..\scripts (for SQL script files)
The necessary files can be found here http://dcx.sybase.com/index.html#1201/en/dbprogramming/deploying-adonet-deploy.html
All these files can be found on a SQL Anywhere Installation 12 in the following directory: C:\Program Files\Sybase\SQL Anywhere 12
Extra info
You need to put dblgde12.dll and dblgen12.dll in the project folder \bin\debug
As for the connection string i'm using this one.
SAConnection conn = new SAConnection("ENG=LXDBSRV;DBN=database;UID=username;PWD=password;POOLING =FALSE;LINKS=tcpip{Host=PC-g};CS=utf-8");
Other way is :
SAConnection conn = new SAConnection("DSN=LXSYDSN;UID=username;PWD=password;DBF=c:\\LxOffice.db");

MySQL Connection with C#

I have a code written in JAVA:
String host = "jdbc:mysql://online/find";
String username = "test";
String password = "test";
And its working fine. But I want to use the same database MySQL with C#. And I am doing this:
try
{
string myConnStr = "Server=//online/find; " +
" Port = 3306; "+
" DATABASE=finder; " +
" UID=test;Password=test;";
MySqlConnection MySqlConn = new MySqlConnection(myConnStr);
MySqlDataAdapter MySqlAdapter = new MySqlDataAdapter();
MySqlAdapter.SelectCommand = new MySqlCommand("Select * from finder.Customer", MySqlConn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(MySqlAdapter);
MySqlConn.Open();
DataSet ds = new DataSet();
MessageBox.Show("Connected");
MySqlConn.Close();
}
But I am getting Error: "Unable to connect to any of the specified mysql hosts"
I even tried with
IP address in connection string but still its not working.
I have checked these posts already:
Unable to connect to any of the specified mysql hosts. C# MySQL
unable to connect to any of the specified mysql hosts. c#
According to the documentation should be:
string myConnStr =
"Database=finder;Data Source=//online/find;Port=3306;User Id=test;Password=test";
However for me Connection strings could be hard to remember.
Its very easy to make a mistake when you write it manually.
One advice is to use the server explorer to connect to your database. Then right click on your database icon > select properties ... you will see the connection string copy and paste .
VoilĂ !
Server Explorer:
Properties:
Did you install the MySQl Connector for Microsoft Application. If yes then add a reference to MySql.dll from your C# application, then use the below connection string
string myConnStr = "server=yourMySqlServerHostorIP; port=MySqlPort;uid=username;pwd=password;initial catalog=dbname";
To download mysql connector go to http://dev.mysql.com/downloads/connector/net/.
Let me know if it works.
My first idea about the issue is "this has nothing to do with param names for username and password". You are not getting an error like:
user "null" cant login
Java and C# work on totally different foundation (Oracle vs. Microsoft) I don't know Java but I think the libraries for connecting to a remote location must be different.
I think the host URL you used is the problem:
Server=//online/find;
I use MySQL with my C# projects and I define the host value as:
localhost or 127.0.0.1
an IP address (xxx.xxx.xxx.xxx)
a host url (my.dbserver.com)
here is a working MySQL connection string:
<add name="dbConnNews"
connectionString="server=xx.xx.xx.xx;database=yyyyy;User
Id=zzzzzz;Password=**********;"
providerName="MySql.Data.MySqlClient" />
Try to connect to the server via IDE Server Explorer --> Data Connections and observe the connection string generated.

C# ODBC ConnectionString

I was currently create a ODBC Connection to the remote server of the web-hosting.
The Access File is at the ftp home directory.
When running in this code , at the m_connection.Open();
var m_result = new DataTable();
try
{
using (OdbcConnection m_connection = new OdbcConnection(connectionDBString))
{
string sql = "SELECT * FROM product";
m_connection.Open();
OdbcDataAdapter dataadapter = new OdbcDataAdapter(sql, m_connection);
dataadapter.Fill(m_result);
m_connection.Dispose();
m_connection.Close();
}
}
catch (Exception e)
{
}
return m_result;
The following exception fails
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified
Is there anyway to claim the dataSource for the ODBC Connection ?
In the cPanel, I only set the DSN and the Path as follows:
DSN : wealthhonesthk-website
Path : e:\virtualhost\domains\wealthhonesthk\home\website.mdb
The below is my part of the web.config
<connectionStrings>
<add
name="ODBCDataConnectionString"
connectionString="DSN=wealthhonesthk-website;Driver={Microsoft Access Driver (*.mdb)};FILEDSN=ftp:/210.245.166.72/home/website.mdb;Dbq=ftp:/210.245.166.72/home/website.mdb;Uid=;Pwd=; curly=false;"
providerName="System.Data.Odbc"
/>
</connectionStrings>
You tend to use a DSN when you don't define a connection string in a config file (like in old VB6 days). Since you're using a config file, you really don't need a DSN. Why not use a connection string like:
Driver={Microsoft Access Driver (*.mdb)};Dbq=ftp://210.245.166.72/home/website.mdb;Uid=Admin;Pwd=;?
Also, having your MDB file mapped to a FTP location may be a problem; why not map a network drive to that location? This way, your connection string might look like:
Driver={Microsoft Access Driver (*.mdb)};Dbq=X:\myNetworkLocation\website.mdb;Uid=Admin;Pwd=;
Lastly, why are you defining a FILEDSN and a Dbq parameter for your connection string?
In short, I'd recommend getting rid of the DSN part of your connection string and use a non-ftp location for your MDB file.
Here is all the information you need on connection strings:
http://www.connectionstrings.com/access
http://www.connectionstrings.com/access-2007
Have a look at following
http://www.connectionstrings.com/
Should help you.
As you are trying to connect to Oracle Database, you might need to have Oracle Client installed.

Categories

Resources