Best way to connect to Interbase 7.1 using .NET C#

左心房为你撑大大i 提交于 2019-12-01 06:38:38

CodeGear offers a free ADO.NET 2.0 driver for registered users of InterBase here:

http://cc.embarcadero.com/item/25497

Note that "registered users of InterBase" includes the free InterBase 2007 Developers Edition. The download says that it's for 2007, but it works fine with InterBase 7, and the InterBase team at CodeGear has told me that they have no problem with people using it for that purpose.

I do not recommend using a driver designed for Firebird, as InterBase and Firebird have somewhat different SQL syntaxes, and differ in other features, as well. In particular, I think that using any driver dependent on fbclient.dll with InterBase is outright dangerous.

I think the Firebird .net provider is the same as the one that's in mono. Both are excelent btw.

The code in the help file works in many situations but not all, especially on Windows 8.1, Windows Server 2012 machines.

Make sure you get the latest InterBase_ADO.NET from embarcadero. The version I updated to was version 16.0.4327.44959 of Borland.Data.AdoDbxClient.dll. (Right click on file, properties, details to see version number). The install also creates a x64 version folder for 64bit even though I did not use it. I targeted x86 with no issues.

This ADO.NET install is not necessary to do on every machine – you just need to include the below files in your project and have Interbase installed on the machine you are running on. I only installed the driver on my development computer.

The install will extract all the necessary files you need to put in you application to connect to the database. It will also create the readme ADO_NET 2_0 Driver for InterBase XE Installation and Usage Instructions.htm file. IMPORTANT NOTE: the DB connection examples in this help htm file do not work 100% of the time. See my code example below for the solution.

No ODBC connection necessary. The list of the files to be included in your .NET project and to be copied local are:

  • Borland.Data.AdoDbxClient.dll
  • Borland.Data.DbxCommonDriver.dll
  • Borland.Data.DBXInterBaseDriver.dll
  • Borland.Delphi.dll
  • Borland.VclDbRtl.dll
  • Borland.VclRtl.dll
  • dbxadapter.dll (x86 or x64 version)
  • dbxint.dll (x86 or x64 version)
  • gds32.dll (from the interbase DB install)
  • interbase.msg (from the interbase DB install)

I found two connection strings that worked. To connect use one of two connection string:

connectionstring1 = "DriverName=Interbase;Database=" + database + ";User_Name=" + userid + ";Password=" + password;
connectionstring1 = connectionstring1 + ";SQLDialect=3;MetaDataAssemblyLoader=Borland.Data.TDBXInterbaseMetaDataCommandFactory,Borland.Data.DbxReadOnlyMetaData,Version=11.0.5000.0,Culture=neutral,";
connectionstring1 = connectionstring1 + "PublicKeyToken=91d62ebb5b0d1b1b;GetDriverFunc=getSQLDriverINTERBASE;LibraryName=dbxint30.dll;VendorLib=GDS32.DLL";

connectionstring2 = “User_Name="+userid+";Password="+password+";Database="+database+";ServerType=0;Charset=NONE;LibraryName=.\\dbxint.dll;VendorLib=GDS32.DLL;GetDriverFunc=getSQLDriverINTERBASE;SQLDialect=3";


GlobalObjects.dbconn = (TAdoDbxConnection)TAdoDbxInterBaseProviderFactory.Instance.CreateConnection();

GlobalObjects.database = databasepath;
GlobalObjects.dbconn.ConnectionString = connectionstring1;  //or connectionstring2
GlobalObjects.dbconn.Open();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!