Firebird error : "operating system directive CreateFile failed" on opening connection - c#

I have narrowed done my problem to small sample where this issue can be easily produced.
Brief -
I am using embeded dll's of firebird for database connectivity i.e. fbembed.dll to connect to firebird databases.
In code, i have three connection strings like this (note additional attribute client library specified in third connection string) -
private const string connection1 = #"User=SYSDBA;Password=masterkey;Database=D:\DB1.fdb;ServerType=1;Charset=UTF8";
private const string connection2 = #"User=SYSDBA;Password=masterkey;Database=D:\DB2.fdb;ServerType=1;Charset=UTF8";
private const string connection3 = #"User=SYSDBA;Password=masterkey;Database=D:\DB2.fdb;ServerType=1;client library=D:\fbembed.dll;Charset=UTF8";
I have two buttons on UI and on first button click i have this code -
FbConnection fbConnection = new FbConnection(connection1);
fbConnection.Open();
On second button click i have this code -
FbConnection fbConnection = new FbConnection(connection3);
fbConnection.Open();
If i create connection with connection string specified as connection3, i am getting FbException "operating system directive CreateFile failed".
However, if i replace the connection string as connection2, it works fine.
Moreover, if i create connection with connection3 and then with connection1 no issue but in case i create connection with connection1 and then connection3, same fbexception coming.
Note, the database specified in connection2 and connection3 is same but only difference is of additional attribute client library.
Why this strange behaviour with embeded firebird. It all works fine in case i have firebird server installed on my system. But, i want to know the issue why it persists in embeded dll's of firebird?

Your issue is related to: http://tracker.firebirdsql.org/browse/CORE-2507
This is a bug in FB engine, fixed in 2.1.4 version.

The problem is that you are connecting to database with Firebird server and Firebird embeeded. The first one locks the database file for open with other proceses(i think you are using superserver).
Another option is that you are using two fbembed.dll from different locations.

This is rather funny but I fixed my Firebird 1.5 + Windows 7 problem!
Installed Firebird as application then ran fb application as admin and the batch file (gbak.exe -b -v -g) also as admin.
Got rid of:
**ERROR**:uavailable database
or
operating system directive CreateFile failed

Related

System.Data.OleDb.OleDbException: 'Could not find installable ISAM.' - MS Access (.accdb) and C# (.Net Framework)

There were few similar questions here, but i couldn't locate any with acceptable answer. or that it would actually work one.
I have create a local storage as .accdb file and tried to connect witch c# to it.
In summary those are the parts needed:
public static string accessConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:\MS_Access_Test_DB.accdb";
OleDbConnection connection = new OleDbConnection(accessConnectionString);
connection.Open();
It always crashes, with an error from description. I had tried to use apostrophes, quotes etc for C:\MS_Access_Test_DB.accdb
I had also tried JET.4.0 with same error & adding Persist Security Info=True; into the mix.
Ok,
The issue as pointed out by Steeeve & Panagiotis Kanavos using is access driver 32bit when i use 64bit architecture, and this will not work. Especially in office/corporation that already has a lot of build in add-ins for office 32 bit. There is also workaround, to install both drivers, but it would require each user to have it, therefore it wasn't solution in my case.
Id much prefer using SQLite, but the tables have to be connected to PowerBI i now that SQLite have to use external drivers to update datasets, therefore for now, this solution was also out.
Considering I cannot force each user to change drivers etc. I tried and saved the access file as .mdb (2002-2003).
So it's either: intalling 64bit driver (proposed initialy) or a workaround (with .mdb):
public static string accessConnectionString = #"Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\MS_Access_Test_DB.mdb";
OleDbConnection connection = new OleDbConnection(accessConnectionString);
connection.Open();
Or:
public static string accessConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\MS_Access_Test_DB.mdb";
OleDbConnection connection = new OleDbConnection(accessConnectionString);
connection.Open();
Important note, there is lot of .accdb functionalities that cannot be used in .mdb, so if you have to use access, than be carefull. If you can, consider SQLite/SQL SE proposed in comment's under my question.
EDIT: I had also messed up the first time... Instead of DataSource I should have had Data Source so it seems to work, despite using Driver 32bit against 64bit app.

How to embed SQLite database files into WPF application

I tried searching the net for this probably simple answer, but without success. I have my WPF app almost ready - using connection strings to connect to my 3 databases (EnteralDB, ParenteralDB, PatientDB) that have several tables.
Problem is that it works while debugging because I hard wired the connection string to specific location (my desktop)
using (SQLiteConnection con = new SQLiteConnection(#"Data Source= C:\Users\Peter\Desktop\EnteralDB"))
But how I can I make the connection string "universal" - meaning that it will work when I create setup for the app and it will install on a new computer? How to embed the database files into the project so they are PART of the project itself and then somehow point with the connection strings to them?
Thank you very much for help!
EDIT Actually, the comment by Clemens is correct. I changed the connection string to just the filename (EnteralDB.db), set copy if newer with content for the database properties and it is working

Local DB in Visual Studio 2015

After a few years, I have returned to writing in C# and I am really struggling here - I would like to have my app to have a local SQL database. I have added Service-based database and "Database1.mdf" was added to my project. I created a table and added some data just to see if it is working but I cannot connect to it. I tried numerous connection strings with no success (Server not accessible).
Do I need to run something else in the background? I thought that I might have a local database and with .NET client I can access it, and I hoped it would work whenever I bring my application (also not requiring any SQL server running). Is that wrong?
If you don't require any SQL server, take a look at SQLite. This is lite SQL database engine. Database is just one file. C# has a great library to SQLite on NuGet: https://www.nuget.org/profiles/mistachkin
SQLite is widely used, event in Android (as a native db engine).
here is what i use to connect. it appears as a Data Connection in Server Explorer.
string con2 = #"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Application.StartupPath + "\\jobfile_2017.mdf;Integrated Security=True;Connect Timeout=30";
when i first started working with these, i used this source 1
it works on PC's that i have nothing installed (not even office) but as i said i'd be interested to know of any shortcomings of this method
I experiencing same problem and decided to move mdf file to static c:\db directory. Connection string was changed to incorporate new file location (AttachDbFile).
But AttachDbFile has some issues also (by some reason one table in db is inaccesible and error is access denied).
So I decided to move to Sqlite. LocalDb has many issues to work with. I read good note to resolve problem: in command line stop/remove/start name of instance. But it nuissance.
Wish you good luck to work with these db files.

Problems with SQLite ADO.net connection and Deployment

Because of what seem to be overwhelming difficulties around Entity Framework, I’m in the process of moving to Dapper. I have an application that uses both a remote MS SQL Server database and a small local database (SQLite). Dapper against the MS SQL Server database is working great, but for some reason I can’t get SQLite connection working.
From the way I understand it, Dapper simply needs an ADO connection. I installed a NuGet package “sqlite-net”, and used the following code to create the connection:
SQLiteConnection con = new SQLiteConnection(“data source=C:\Data\OneDrive\Data\TestDB.sqlite”);
and
SQLiteConnection con = new SQLiteConnection(“data source=C:\Data\OneDrive\Data\TestDB.sqlite; Version=3”);
Neither one of these work and they throw an exception “Could not open database file”. The file SQLite.cs (coming from the NuGet package) threw the error.
Because of my past problems with deployment, I’ve hesitated installing the downloaded files from System.Data.sqlite.org.
Please can someone help me?
Looking at the nuget package and specifically the SQLite.cs file:
https://github.com/praeclarum/sqlite-net/blob/master/src/SQLite.cs
I see the following constructor definition (line 180):
public SQLiteConnection (string databasePath, bool storeDateTimeAsTicks = true)
: this (databasePath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create, storeDateTimeAsTicks)
{
}
This shows that the first argument is just the path, and should be called like:
SQLiteConnection con = new SQLiteConnection(#"C:\Data\OneDrive\Data\TestDB.sqlite”);
The # sign escapes the \ characters from being interpreted as character codes. These two issues look like the problem that you have and I would try it out and see if it works.

Connecting C# app with Oracle 10g: ORA-12154: TNS:could not resolve the connect identifier specified

I am a beginner in working with databases. I am trying to access Oracle10g database from a c# application. But when I do so i get this error:
ORA-12154: TNS:could not resolve the connect identifier specified"
I'm using the following code:
string oradb = "Data Source=ORCL;User Id=system;Password=goodbye;";
OracleConnection conn = new OracleConnection(oradb); // C#
conn.Open();
Is there an error in the connection string oradb?
Start the Visual Studio, open View menu + Server Explorer.
Right mouse click on Data Connection + Add Connection + Select Oracle Database
server Name : localhost or name of your machine, set username & password and click on Test Connection to verify the above parameters. Press OK if test is succeeds.
From properties windows you can obtain connection String and it should be look a like:
Data Source=localhost;Persist Security Info=True;User ID=scott;Password=***********;Unicode=True
Oracle is just stating that it can't find the database.
If you're running a local Express Edition database, you should be able to just use XE as an instance name, and everything should already be set up, otherwise you can most easily add it to tnsnames.ora.
To find the correct tnsnames.ora to change, you can try (from the command prompt)
tnsping ORCL
That will tell you which files Oracle is using to try to find the database. If tnsping is an unknown command, you may have to search for it and go to the correct place before running it.
One you found the correct tnsnames.ora, you need to add the instance ORCL to it. There should be an existing file with examples, the syntax of that file is too complex to answer here, if you need help, Oracle has quite extensive documentation.
This is a very common oracle error. Simply put, it means that you have named the database you wish to be connected to and Oracle doesn’t know who the heck you’re talking about. I suggest 6 Steps to fix ORA-12154:
Check instance name has been entered correctly in tnsnames.ora.
There should be no control characters at the end of the instance or database name.
All paranthesis around the TNS entry should be properly terminated
Domain name entry in sqlnet.ora should not be conflicting with full database name.
If problem still persists, try to re-create TNS entry in tnsnames.ora.
At last you may add new entries using the SQL*Net Easy configuration utility.
More informations on oracle site or here : http://turfybot.free.fr/oracle/11g/errors/ORA-12154.html

Categories

Resources