Firebird database in Embedded in C# with Entity Framework - c#

Can Firebird database be used in embedded mode like SQLite? When working with Entity Framework in SQLite, if I write the database name in the connectionString (example.db), when I run it, a new database is opened in the bin folder. Can I use Firebird the same way?
Or is there a different way to use Firebird without installing its server.

Yes, you can use Firebird Embedded with FirebirdSql.Data.FirebirdClient. In the connection string you must specify ServerType=1 (or ServerType = FbServerType.Embedded when configuring through code), and only specify the path to the database (no host name).
However, to be able to do this, you must include all the necessary binaries for Firebird Embedded in your project yourself (or make sure it is on the PATH when you run your application).
That is, when you deploy your application, the directory containing your application must contain fbclient.dll, plugins\engine13.dll (Firebird 4.0, engine12.dll for Firebird 3.0) and all required supporting files, or a directory containing those files must be on the PATH.
In its simplest form, you can obtain those files by downloading the Firebird 4.0 zipkit of the appropriate bitness from the Firebird 4.0 download page. You can optionally remove all the .exe and .bat files, security4.fdb and directories doc, examples, help, include, lib, misc, and system32, although this still leaves some files that are not strictly necessary.
You may also want to read Problem connecting to Firebird 3 embedded with C# in .NET.
In short, it is possible, but it is not as simple as a SQLite deployment.

Related

Creating .NET Core REST API with embedded database

Is it possible to create a .NET Core REST API which will contain an embedded database (possibly .mdf file) and still deploy it on other OS like Linux? I know that SQL Server can be installed on Linux but can this be done silently within the application's installation program?
There are a number of different options. Some that you might want to consider:
SqlLite (relational)
LiteDb (nosql)
DBreeze (key-value)

How to make odp.net 12c to work with other oracle client

I have oracle 10g client(full) and 11g instant client installed on my machine.
I am trying to use ODP.NET 12c. Here is what I did.
Added Oracle.DataAccess.dll to References.
Copied OraOps12.dll to the folder where my executable is.
When running I got "Unable to load DLL 'OraOps12.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)".
I think it could be due to dependency issue. So I further copied 12c's
oci.dll
oraociei12.dll
orannzsbb12.dll
I then still got other dependency errors. I don't want to copy the whole InstantClient though.
My goal is to get the app to work with other versions of Oracle client.
Our customers have different version of Oracle client installed. So any way to get the app (ODAC12c) work with customers' current version of Oracle client without having to install 12c client?
Thanks,
Update:
I forgot to mention a few things
my ODAC is 32bit and I compiled my app on x86.
I didn't use Oracle.ManagedDataAccess.dll because it does not include BULKCOPY classs. If anyone knows a version of Oracle.ManagedDataAccess.dll that includes bulkcopy class please let me know.
Our customers already has different versions of Oracle client installed for other apps and they don't want to change their environment just for this new app. So my goal becomes to make one version of ODAC in my app work with different versions of existing Oracle client (each customer environment is different). Is this possible and if yes, how?
You know, I just spent 5 minutes looking for the guy that I remember attempting this before...and it turned out to be you shawn ;).
Honestly, to rely on what the client has installed is a crap-shoot. I would use the full xcopy package, get it working, and then work backwards, deleting what is not needed.
Don't run the install.bat that comes with it. Doing so adds registry entries that aid in locating the unmanaged binaries, but you also risk messing with a client installed copy.
Drop the whole xcopy install into your app's folder as a subfolder.
Instead, set the DllPath to this new subfolder
Example:
<oracle.dataaccess.client>
<settings>
<add name="DllPath" value="C:\app\user\product\11.1.0\client_1\BIN"/>
Then set the Oracle_Home environment variable
Example:
Environment.SetEnvironmentVariable("ORACLE_HOME", #"C:\app\user\product\11.1.0\client_1\");
This article does something similar:
http://dbaportal.eu/2013/02/22/true-xcopy-runtime-for-oracle-odp-net-application/
He even adds a policy to redirect in case he has referenced projects that reference a particular version of Oracle.DataAccess.dll
He adds his oracle home with a batch file though. The part I'm not so sure of is that he also adds his new xcopy install to the path with that same batch file. DllPath should take care of that, but if I'm wrong, you can also do that at runtime:
Environment.SetEnvironmentVariable("PATH", #"C:\app\user\product\11.1.0\client_1\BIN");
From here, I'd setup some basic unit tests using all the ODP.net functionality you are using and get some positive tests and then work backwards - start deleting what you don't need, running your tests each time. You might be able to use sysinternals procexp to show loaded dlls (or procmon to show access to the files). Just loading your tests might be enough to lock the files so you can delete all the ones that aren't locked.
I'm not sure doing this is supported. Then again Oracle does list "the current application's directory" in the unmanaged search order so they didn't close the door either.
EDIT:
Found one of the links of other people doing this:
http://alderprogs.blogspot.com/2009/04/deploying-odpnet-with-oracle-instant.html
I'm not sure why but they download the instant client separately (it's already part of the xcopy package).
EDIT 4/15/2016: If you're reading this these days note two things. 1) I don't think setting the environment variables are necessary if you are already setting DllPath. 2) I don't think this is worth doing when the managed provider now only requires one or two dlls.
It's a bad idea to copy single DLL's to different directories and hope it will work.
In general ODP.NET provider works only together with corresponding Oracle Client, i.e. in order to use ODP.NET 12 you must also install Oracle Client 12. Same applies for version 11 or 10.
Only exception is the ODP.NET Managed Driver, there you need only a single DLL (Oracle.ManagedDataAccess.dll).
Furthermore the architecture (32 bit vs. 64 bit) has to match.
In case you use OLEDB provider it's even not possible to have more than one provider installed (for each architecture) - unless you hack your system by manipulating PATH variable and Registry all the time.
My proposal would be: Remove all Oracle Clients from your machine and install only one (or one per architecture) Oracle Client properly. It's very unlikely that an application works with one Oracle Client version only. It is also a good approach to install both 32bit and 64bit on one machine, follow this instruction to do it: Install Oracle x86 and X64 on one machine
In case you really need to test your application with different Oracle Client version, setup a couple of test-PC (maybe in a Virtual-Box) each with a different Client version. Otherwise it will be very challenging to handle it.
Update:
I think each (Unmanaged) ODP.NET version works only with according version of Oracle Client. Maybe by chance there are some combinations which work out but in general the versions should match.
I see two different solutions:
(1) Ask your client to install his Oracle Client including ODP.NET. He can choose the version, only the architecture (32 bit or 64 bit) has to match. Then you don't supply any ODP.NET with your application.
In your *.csproj, resp. *.vbproj file define your reference like this:
<Reference Include="Oracle.DataAccess">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
Attributes like Version=... or processorArchitecture=... are not required. Then your application should run with any Oracle/ODP.NET version.
Your customer can download ODP.NET provider from here: Oracle Data Access Components (ODAC) for Windows Downloads and install it on top of existing Oracle Client installation. In readme.txt it says "The files of this zip file is NOT to be installed on top of an existing
Oracle Universal Installer (OUI) based Oracle Home installation.", however I don't see any reason why not doing it. It works well, you just have to carefully provide correct folder for existing Oracle installation and correct ORACLE_HOME name and do not install dependencies.
(2) In your setup script/exe determine the Version of customer installed Oracle Client and copy according ODP.NET to customer machine.
In order to determine version of Oracle Client you can to search for file oci.dll in folders provided by PATH environment. oci.dll is a normal .NET assembly, so you can read out the version easily.
For a proper installation of ODP.NET follow the file configure.bat which is part of downloaded ODP.NET XCopy version. In my opinion this batch file is easy to understand.
Basically it does
1 - Copy file Oracle.DataAccess.dll to target machine
2 - Copy different resource files *\Oracle.DataAccess.resources.dll to target machen
3 - Add these DLL's to the GAC. This can be done by gacutil.exe or OraProvCfg.exe (included in downloader ZIP file) or your setup application provides this operation.
4 - Make a few Regristy entries. Newer ODP.NET versions write/read into HKLM\SOFTWARE\Wow6432Node\Oracle\ODP.NET (for 32 bit), resp. HKLM\SOFTWARE\Oracle\ODP.NET (for 64 bit). Older ODP.NET versions use HKLM\SOFTWARE\Oracle\KEY_{ORACLE_HOME_KEY}\ODP.NET\ (for 64 bit), resp HKLM\SOFTWARE\Wow6432Node\Oracle\KEY_{ORACLE_HOME_KEY}\ODP.NET\ (for 32 bit) instead
That's it, you should be able to include this in your setup.

IBM db2 driver deployment / installation

I'm trying to connect to IBM DB2 database with C# application. At first I've installed IBM Data Server Driver Package, which, according to the documentation is for applications using ODBC, CLI, .NET, OLE DB, PHP, Ruby, JDBC, or SQLJ, use IBM Data Server Driver Package. Then I thought I could use IBM.Data.DB2 assembly and happily connect. It didn't work at all, as the app kept crashing while looking for db2app.dll in its current working directory.
Then I installed IBM Data Server Client, which has this dll in "bin" directory, which I added to system path. That didn't help, so I copied it to my app's build directory, and it now works. But I don't think that is correct, as I also had to copy msg\en_US\db2nmp.xml file to my build directory to get exception error texts.
I think it's wrong to copy all these files from DB2 installation, and I should somehow be able to force IBM.Data.DB2 assembly to look for its required files in the system path, not in its working directory. I also think that Data Server Driver Package should be enough, but I wasn't able to do anything with IBM.Data.DB2.dll until I installed the larger Data Server Client.
I assume that the problem is on my end, not with IBM, so I'm doing something obviously or subtly wrong.
My question is: How do I use the smaller IBM Data Server Driver Package with .NET application?
I think you are looking for this information that is available in DB2 manual:
http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.swg.im.dbclient.adonet.doc/doc/c0010960.html
And perhaps this helps also:
http://www.ibm.com/developerworks/wikis/display/DB2/DB2%20and%20.NET%20FAQs#DB2and.NETFAQs-WherecanIfindtheDB2.NETproviderandVSAddins%3F
In general, I think you should've installed IBM Database Add-Ins for Visual Studio from here(Requires IBM Registration):
https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=swg-daivs

Including MySQL Connector/ODBC 5.1 to C# application

I am using System.data.odbc with "Driver={MySQL ODBC 5.1 Driver}" in the connection string. However, I have not realised there is MySQL connector installed on my PC so however I have not referenced it, it doesn work without it.
Now I need to distribute it embed in the app. I have downloaded MySQL Connector/ODBC 5.1 files, but with Add reference it says "The file is not accessible...make sure its valid COM.." etc.
Thank you
MySQL Connector/ODBC is, as the name suggests, just an ODBC driver for connecting to MySQL. It's not specifically designed for .NET and you can't embed it in your .NET applications in any way. It will need separate installation on any machine where you need to use it.
MySQL Connector/Net is a fully managed ADO.NET provider for MySQL. It's tailor-made for .NET and doesn't require the installation of any other software. It's easy to reference and distribute in your .NET applications, you'll just need to use the System.Data.MySqlClient namespace and objects rather than System.Data.Odbc.
You can embed the .NET DLL, but not the driver itself. You'll need to install MySQL Connector on every computer that runs your application.
The only thing u need is Mysql.Data.Dll
You don't need to install the complete connector, everything u need is in there.
That also counts for the end user, they also only need the dll

SQL CE 3.5 deployment problem, concerning interop between C# and C++

We have a situation where a C# application is working with SQL CE 3.5 . To allow for a legacy program to use some of its features we have produced a C++ dll which uses interop to extract the info that it needs from the C# program. For this to work, the C#-program needs to access the database. Its not a very complex scenario.
When trying to deploy with a private install some problems occur though.
There is no problem with the C# program, it can access the database and work with it without any problems.
But when trying to access functions in the C#-program through the C++ interop which forces the C#-program to access the database, we get a crash with the exception saying that "...the Provider: System.Data.SqlServerCe.3.5 is not installed".
This is obviously because we cannot add a App.config file to the executing program.
How can we get around this? Is there another way to fix this? Any other forms of SQL CE 3.5 install methods are out of the question. So we must get this to work.
Regards,
P
Edit:
I'm not working against SQL CE directly, but through Linq2SQL. I have tried to add config files to all my dll's, it does not help. It seems to only matter if the executable file have got a app.config.
The exception thrown says - The provider System.Data.SqlServerCe.3.5 is not installed.
And the latest function to be called according to the stack trace is
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Initialize(...).
Edit 2
I have added all the files necessery for the deployment to work. As I wrote above, it works if I use the program dll (which uses Linq 2 Sql) through a .net executable with a app.config file that specifies where to look for the SQL CE 3.5 dll. Deployment will not work with only the files, an app.config file is necessary.
The problem is that we have to use the dll file through a C++ executable which have no means of telling .net where to look for the Sql Ce 3.5 dll.
add the following files to your application folder:
sqlceca35.dll
sqlcecompact35.dll
sqlceer35E.dll
sqlceme35.dll
sqlceoledb35.dll
sqlceqp35.dll
sqlcese35.dll
System.Data.SqlServerCe.dll
then it will work.
that is necessary if you have not explicitely installed sql server ce 3.5 on the target machine (which is case for most deployments i think).
You can add a foo.dll.config file and make sure it lives alongside the DLL. You just need to make sure that you have code in your DLL to determine where it lives on disk, and read the configuration from the same location.
Good luck!
This is obviously because we cannot add a App.config file to the executing program.
Why not? Okay, so Visual Studio won't automatically build the config file and rename it and move it to the output directory, but have you tried a .exe.config file alongside your C++ application?
I have also seen an instance where the System.Data.SqlServerCe.dll in the GAC was the wrong file version and I had replace the dll in the GAC from a cmd command prompt.
The point about the files having to be in the folder is true - unless the GAC gets itself confused by have multiple versions
Do not use LINQ, but use SqlCeConnection, SqlCeCommand etc for the methods you call from your C++ program

Categories

Resources