DB2 Connection using C#.Net - Ms Visual Studio - c#

I am trying to connect Db2 through c#.net
DB2Command MyDB2Command = null;
String MyDb2ConnectionString = "database=<alias>;uid=<username>;pwd=<password>;";
DB2Connection MyDb2Connection = new DB2Connection(MyDb2ConnectionString);
MyDb2Connection.Open();
Getting below error on MyDb2Connection.open():
SQL1159 Initialization error with DB2 .NET Data Provider, reason code 10, tokens 0.0.0, 9.7.4,
Kindly help me to resolve the issue.
In application folder I have already put db2app.dll and db2app64.dll
Db2 Version: 9.7.4

Related

Visual Studio 2022 (.Net 6) with Oracle.ManagedDataAccess,Core (2.18.3 or higher) getting ORA-12607: TNS: Connect timeout occurred

Problem:
I am trying to use the Oracle.ManagedDataAccessCore (2.18.3 or higher) version to access and to query the Oracle Database but the program kept throwing ORA-12607: TNS: Connect timeout occurred when I tried to run a query using the following codes below.
public async Task<ActionResult<IEnumerable<EqpStateDto>>> GetEqpState()
{
var query = "SELECT * FROM MAC_STATE";
using (var connection = _dapperContext.CreateConnection())
{
var eqpStates = await connection.QueryAsync<EqpStateDto>(query);
return Ok(eqpStates.ToList());
}
}
Background:
I've tried using the Oracle.ManagedDataAccessCore 2.12.0-beta2 version and it is WORKING. Somehow it is not working if I were to use the 2.18.3 version or higher.
I have tried setting the pooling to false ("Pooling=false") and increased the connection timeout ("Connection Timeout=60") but it doesn't resolve the issue.
Is there any configuration that I need to include in order for it to work?

Synchronize two SQL Server database using Dotmim sync framework

I have a WinForms database driven application that I want to make it work in online/offline mode using Dotmim sync framework that I find an article by their author here.
The documentation for the library is here
this is my code to sync the two SQL Server databases one is localdb and the other one is now on the SQL Server Management Studio for the testing purpose:
string connect = #"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=bright_square_db;Integrated Security=SSPI;AttachDBFilename=D:\Folder\project_file\bright_square_db.mdf";
string constring = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlSyncProvider serverProvider = new SqlSyncProvider(constring);
SqlSyncProvider clientProvider = new SqlSyncProvider(connect);
SyncAgent agent = new SyncAgent(clientProvider, serverProvider, new string[] { "I have listed all the tables here" });
var progress = new SynchronousProgress<ProgressArgs>(s => MessageBox.Show($"{s.Context.SyncStage}:\t{s.Message}"));
var syncContext = await agent.SynchronizeAsync(progress);
MessageBox.Show(syncContext.ToString());
But, when I try to run the code. I am getting this error
The columns that indicated in the error are for a table that created by the sync process named "scope_info" inside the SQL Server database.
I have solved the problem by swapping the client and server connection string link in the third and fourth line of the above code. I don't know what exactly cause the problem, but lastly this changed makes the code work for me.

SEHException on OleDb connection open

I'm developing a small application that will simplify logging, it does so by adding some inputs to an MS Access database through OleDB.
let private conn = new OleDbConnection(connectionString)
let private submitCmd date wins =
let cmd = new OleDbCommand("INSERT INTO ArenaStats ([Date], [Wins]) VALUES (#Date, #Wins)",
Connection = conn, CommandType = CommandType.Text)
["#Date", box date; "#Wins", box wins]
|> List.iter (cmd.Parameters.AddWithValue >> ignore)
cmd
let private submit date wins =
try
conn.Open()
(submitCmd date wins).ExecuteNonQuery() |> ignore
finally
conn.Close()
[<CompiledName "AddEntry">]
let addEntry(date:DateTime, wins:int) =
submit date wins
Now testing this through FSI works just as expected. However, when I consume this API from a C# WPF project it will throw an SEHException at conn.Open(). I am really scratching my head over why this is happening.
Edit
As suggested, I have also tried to implement the same code purely in C# and in the same project, it will throw the same exception at the same place but I am posting the code below for reference.
class MsAccessDatabase : IArenaWinsDatabase {
private OleDbConnection connection = new OleDbConnection(connectionString);
private OleDbCommand SubmitCommand(DateTime date, int wins) {
return new OleDbCommand("INSERT INTO ArenaStats ([Date], [Wins]) VALUES (#Date, #Wins)") {
Connection = connection,
CommandType = System.Data.CommandType.Text,
Parameters = {
new OleDbParameter("#Date", date),
new OleDbParameter("#Wins", wins)
}
};
}
public void Submit(DateTime date, int wins) {
try {
connection.Open();
SubmitCommand(date, wins).ExecuteNonQuery();
}
finally {
connection.Close();
}
}
}
With some help from Philip I was able to figure it out. It seems that by default FSI is configured to run in 64-bit by default while the WPF project is set to "prefer 32-bit". Changing the target platform for the WPF project to 64-bit resolved the issue.
When trying to run the following code:
var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=Excel 12.0;", FilePath);
OleDbConnection OleDbConnection = new System.Data.OleDb.OleDbConnection(connectionString);
OleDbConnection.Open();
An SEHException exception is thrown at runtime, with the error message 'External Component has thrown an Exception'
This will usually occur when the build configuration platform in Visual Studio is incorrect, this can occur in both build configuration platforms, x86 and x64.
This is due to a mismatch between the build configuration platform of your project and the Microsoft Access Database Engine which is installed on your machine.
In order to resolve this error:
Change the build configuration platform in Visual Studio - make sure it matches the Microsoft Access Database Engine version on your machine
Recompile and run your project
The run time error should now be resolved
I know this is a really old thread, but I just ran into the same problem with a different solution.
When I installed the Access Database Engine 2016 Redistributable (x64) for the ACE provider the installer gave me an error that VCRUNTIME140.DLL wasn't installed, but the installer completed anyways and the ACE provider was available.
Uninstalling the Access Database Engine, installing the VC++ 2015 Redistributable R3 (https://www.microsoft.com/en-us/download/confirmation.aspx?id=52685), then re-installing the Access Database Engine solved the problem.

C# Oracle Connection with MSDAORA.1

I have a Excel-Sheet connected with a Oracle Database with MSDAORA.
Connection String in Excel is
Provider=MSDAORA.1;User ID=xxx;Password=xxx;Data Source=yyy.com
CommandType is Tabledirect and CommandText is "zzzzzz"."ZZZZZZZZ"
Integrated Security is Windows Authentication
So i createt a small Test App for connecting me to the Oracle-DB with C#.
It seems the Connection String is the same, but its not working.
Error Message : OLEDB Exception - Error executing OLEDB Procedur
Using VS2012 / NET3.5 /
tbConnectionString.Text = #"Provider=MSDAORA.1;User ID=xxx;Password=xxx;Data Source=yyy.com";
tbCommandText.Text = #"""zzzzzzz"".""ZZZZZZZZZZ""";
myOleDbConnection = new OleDbConnection(tbConnectionString.Text);
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();
myOleDbCommand.CommandType = CommandType.TableDirect;
myOleDbCommand.CommandText = tbCommandText.Text;
myOleDbConnection.Open();
THX
Is an issue of Operating system and VS version.
Because I faced same problem before when using Win 7.
After diagnosing the issue , we find solution of Oracle.DataAccess.
Check out the support of msdaora.1.

SQL Server 2012 Error 26

I downloaded SQL Server 2012 Express. Using http://www.mssqltips.com/sqlservertip/2694/getting-started-with-sql-server-2012-express-localdb/. I created a local database. Now when I tried to connect to that database using Visual Studio 2010 it throws me error 26
Here is my code:
using(SqlConnection connectionString = new SqlConnection(#"Server=(localdb)\SQLEXPRESS;database=master;Trusted_Connection=True;")
{
connectionString.Open(); //error 26
sql = "insert into Main ([Cable Length1], [Cable Length2]) values(#3',#5')";
using (SqlCommand cmd = new SqlCommand(sql, connectionString))
{
cmd.Parameters.AddWithValue("#3'", 1);
cmd.Parameters.AddWithValue("#5'", 2);
cmd.ExecuteNonQuery();
}
}
Also, I am able to login through SQL Server Management Studio 2012. Can anyone tell me what am I missing?
Ignoring all the other problems1, you should make up your mind as to whether you're using SQL Server LocalDB or not. I am highly doubtful you've made a private LocalDB instance called SQLEXPRESS.
You likely want something along the lines of:
new SqlConnection(#"Server=(localdb)\v11.0;Trusted_Connection=True;")
Or
new SqlConnection(#"Server=.\SQLEXPRESS;Trusted_Connection=True;")
1 being the following:
Your SqlConnection is called connectionString.
Parameters with quotes in their names.
Using master and then trying to insert into a table called Main. System databases are for the system. You are not the system.
I'd expect to see something along the lines of:
using (var connection = new SqlConnection(#"Server=(localdb)\v11.0;Database=MyDatabaseName;Integrated Security=true;")
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO [Main] ([Cable Length1], [Cable Length2]) VALUES(#3, #5)";
command.Parameters.AddWithValue("#3", 1);
command.Parameters.AddWithValue("#5", 2);
command.ExecuteNonQuery();
}
}
I got the solution: Make sure you are connected to Database and when you launch sql management studio under server name-->select browse for more-->select database engine and then select your local database. You should see the Green Icon and then you do get connected. Thanks for the help guys!

Categories