views:

632

answers:

1

Hi,

I have an C# winforms app that works fine on all our XP machines. We want to put it on a new Win 2008 64 bit server and it breaks on the following code:

using (OdbcConnection oConn = new OdbcConnection())
{
    oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=" + filePath + ";Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
    oConn.Open();

    OdbcCommand oCmd = oConn.CreateCommand();
    oCmd.CommandText = "SELECT DISTINCT Mid(POSTCODE,1,Len(POSTCODE)-2) AS sector FROM " + shortfilename + ".dbf;";

    OdbcDataReader dr = oCmd.ExecuteReader();
    try
    {
        while (dr.Read())
        {
            lstSectors.Items.Add(dr.GetString(0));
        }
    }
    catch
    {
        string err = "Error!";
    }
    finally { dr.Close(); }
}

The error I get is:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

If I look at the 64 bit ODBC Data Source Admin, there are no dBASE drivers there - but in the 32 bit (C:\Windows\SysWOW64\odbcad32.exe), they are - how do I get the application to use the 32 bit drivers?

Many thanks

+1  A: 

It is not possible to use a 32-bit ODBC driver from a 64-bit application. 64-bit processes cannot call into 32-bit DLLs (not directly anyway). Microsoft has a KB article about the 64-bit ODBC administrator that might help.

Mark Wilkins
This is the first time I've used a 64bit OS so excuse my ignorance and total lack of knowledge on these things.The app was written in VS2005, and on the server we have VS2008 so it has been opened and converted in that. Does that make this version of the app 64 bit? Having looked at the article, it states the workaround is to create the data source in the 32-bit admin tool, but the problem is, i'm querying .dbf files and the file location changes each time, so how can I create a data source..? Thanks
leddy
If you build your project with the "Platform Target" set as "Any CPU", then it will run as a 64-bit process on a 64-bit OS (and it would be looking for 64-bit drivers). You can force it to be 32-bit and then it would look for the 32-bit drivers. But I think the "any cpu" option is best. It sounds like you do not have the 64-bit drivers installed. Run windows\system32\odbcad32.exe on it and see if they exist. If not, run the mdac v7 install. They are supposed to be included in that version.
Mark Wilkins