Subscribe to this thread
Home - General / All posts - Error when connecting to map file from c# application using ODBC
Brad Curtis3 post(s)
#20-Jan-23 05:54

Hi All,

I'm trying to connect to an existing map file from a c# console application using the ODBC driver that comes with version 9 (https://manifold.net/doc/mfd9/manifold_odbc_driver.htm)

When trying to connect to the data source I get the following error:

ERROR [IM004] [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

Is anyone aware of a better way to connect to Manifold from C#? or has dealt with a similar issue? Essentially we just want to be able to query the results of data within Manafold to serve up to another application.

Thanks

oeaulong

460 post(s)
#20-Jan-23 15:36

Can you provide details on *how* you are connecting from the console app?

Brad Curtis3 post(s)
#21-Jan-23 00:32

Hi,

Currently trying to connect to the following (which works for other ODBC sources)

OdbcConnection DbConnection = new OdbcConnection("DSN=<ManifoldODBCSourceICreated>");

DbConnection.Open();

I've also tried using it in the following way:

var filePath = "<pathToMapFile>";

var connectionString = "DRIVER={Manifold 9.0 Project Driver (*.map)};DBQ=" + filePath + ";Unicode=True;DSN=Default;";

OdbcConnection DbConnection = new OdbcConnection(connectionString);

DbConnection.Open();

Both give the same error (but am able to open other odbc sources such as sqlite just fine)

Thanks

oeaulong

460 post(s)
#21-Jan-23 00:38

can you connect to the DSN via another method, like excel, mfd8, another dbclient?

Brad Curtis3 post(s)
#21-Jan-23 00:43

I am able to use it as a data source in Manifold itself (essentially opening another map file as a data source, so I believe that the DSN itself is working)

Thanks

adamw


10,281 post(s)
#25-Jan-23 12:57

Does the main function in the C# app has the STAThread attribute applied? If not, apply it.

Also, you don't have to use the ODBC driver to get to data using Manifold from .NET code. You can add EXTNET.DLL as a reference, create a Root object, then open the desired file (eg, using Application.CreateDatabaseForFile), etc. The main function will have to have the STAThread attribute as well.

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.