问题
When i run the c# code with firebird db as backend it shows.My code is plain and simple then why is it showing such an error??
An unhandled exception of type 'System.BadImageFormatException' occurred in FirebirdSql.Data.FirebirdClient.dll
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
private void button1_Click(object sender, EventArgs e)
{
string connectionString =
"User=SYSDBA;" +
"Password=masterkey;" +
"Database=TESTFB.fdb;" +
"DataSource=localhost;" +
"Port=3050;" +
"Dialect=3;" +
"Charset=NONE;" +
"Role=;" +
"Connection lifetime=15;" +
"Pooling=true;" +
"MinPoolSize=0;" +
"MaxPoolSize=50;" +
"Packet Size=8192;" +
"ServerType=1;";
//string sql = "INSERT INTO STUDENT(ID,NAME) VALUES(@ID,@NAME)";
string sql = "SELECT * FROM STUDENT WHERE ID=@ID AND NAME=@NAME;";
try
{
FbConnection con = new FbConnection(connectionString);
con.Open();
FbCommand cmd = new FbCommand(sql, con);
cmd.Parameters.Add("@ID", FbDbType.Integer).Value = Convert.ToInt32(textBox1.Text);
cmd.Parameters.Add("@ID", FbDbType.VarChar).Value = textBox2.Text;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (FbException ex)
{
MessageBox.Show("5--" + ex.Message);
}
}
回答1:
The problem is that you are trying to use embedded (ServerType=1
), but the fbembed.dll
(or fbclient.dll
) on your path does not match the runtime bitness (eg 32 bit vs 64 bit).
Are you sure you want to use Firebird embedded? The rest of the configuration string seems to suggest you want to connect to a normal Firebird server, in which case ServerType=0
(or just leaving it off) is better as then you don't have a dependency on a native dll.
来源:https://stackoverflow.com/questions/34561399/firebird-db-connection-string