如何使用 C# 获取所有 ODBC 的列表或访问 64 位机器中的数据源



我的应用程序现在仅支持 64 位,我需要获取机器上存在的所有 ODBC 或访问数据资源或新创建的机器。

下面的代码用于获取 32 位列表,但现在它在调用SQLAllocEnv方法时崩溃。

[DllImport("odbc32.dll")]
private static extern int SQLDataSources(
int EnvHandle, int Direction, StringBuilder ServerName,
int ServerNameBufferLenIn, ref int ServerNameBufferLenOut,
StringBuilder Driver, int DriverBufferLenIn, ref int DriverBufferLenOut);
[DllImport("odbc32.dll")]
private static extern int SQLAllocEnv(ref int EnvHandle);
[DllImport("odbc32.dll")]
private static extern int SQLFreeEnv(int EnvHandle);

那么,有谁知道如何解决这个问题?

在某篇帖子中,我发现将int数据类型更改为long将起作用,是的,它也适用于我的情况。

最新更新