The type 'System.Data.Common.DbTransaction' is defined in an assembly that is not referenced. You must add a reference to assembly

StackOverflow https://stackoverflow.com/questions/23676567

  •  23-07-2023
  •  | 
  •  

Question

Welcome. I am trying to write an application on Windows mobile 6 that connects to a Firebird 2.5.2 database (using visual studio 2008 and Forms). I wrote this piece of code:

  static public void Execute(FbTransaction tr, string sql, bool commit)
    {
        FbConnection cn = null;
        FbCommand cmd = null;

        if (tr != null)
        {
            cmd = new FbCommand(sql, tr.Connection, tr);
        }
        else
        {
            cn = new FbConnection(ConnString());
            cmd = new FbCommand(sql, cn);
        }

        if (cmd.Connection.State == ConnectionState.Closed)
        {
            cmd.Connection.Open();
        }

        cmd.ExecuteNonQuery();

        cmd.Dispose();

        if (cn != null)
        {
            cn.Close();
            cn.Dispose();
        }
    }

I get error in the lane 1st (Execute highlighted)

Error 1 The type 'System.Data.Common.DbTransaction' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I have System.Data version 2.0.0.0 added to my references. Would appreciate any help.


I have found the solution. For those who will face similar problem in the future, here is how I've done it: To get it working with windows forms 64 bit in VS 2008 (.net 3.5) and firebird 2.5.2 (newest at the moment), first thing you need to do is download Firebird EMBEDED win x 64 package http://www.firebirdsql.org/en/firebird-2-5-2-upd1/

Next, go for source code version of .NET provider, for me worked this one (if u code in VS2010 or later try more recent versions) http://sourceforge.net/projects/firebird/files/firebird-net-provider/2.5.2/

Open it, and in the Configuration manager compile it under x64. (remember to add reference for System.Data for specific .net version, I think I used 2.0.0.0)

Now, create your desirable winform project, and include all .dll's from the embeded Firebird package you have downloaded in step 1 (Add existing item to your project's root directory)

Add reference to your newly compiled FirebirdSql.dll, I had it in my \NETProvider-2.5.2-src\NETProvider\source\FirebirdSql\Data\bin\x64\Debug\FirebirdSql.Data.FirebirdClient.dll

And enjoy. Bonus ->

string path to local Firebird server is tricky, so here is what worked for me

     string Firebird_path = "User=SYSDBA;Password=masterkey;" +
           "Database=localhost:L:\\DBS\\DBS.FDB; " +
           "DataSource=localhost;Charset=NONE;";
Was it helpful?

Solution

Have you referenced the Firebird .NET Provider in your project?

You can find it here. It can be added as a NuGet package as well.

OTHER TIPS

The class FbTransaction implements the DbTranaction interface. This means that if you use FbTransaction in your code, then at runtime this interface needs to be loaded as well, so you need to reference the assembly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top