在某些平台上使用odbc时出错(32位对64位)

时间:2014-12-16 22:27:20

标签: c# windows-8 odbc 32bit-64bit installshield

我们正在使用Installshield来安装我们的一个应用程序。

其中一个步骤需要输入Oracle实例的连接字符串。

在Installshield中,我们使用ODBC打开oracle连接并在数据库上运行一些脚本。

我们在Windows 8或Windows 2012服务器上安装时遇到包问题。

我们在Installshield中遇到此错误,与ODBC版本有关:

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Source: Microsoft OLE DB Provider for ODBC Drivers SQL State: IM002 Native Error: 0 

我们知道它与ODBC版本(32位对64位)有关,它们都位于此处:

C:\Windows\SysWOW64\odbcad32.exe

OR

C:\Windows\System32\odbcad32.exe

为了真正测试这个问题,我创建了一个控制台应用程序,它将打开和关闭odbc连接并将错误记录在文本文件中。

这是小样本:

using System.Data.Odbc;
using System.IO;

static void Main(string[] args)
{
    TextWriter tw = new StreamWriter("Errors.txt");
    Console.WriteLine("Enter the Server Name:");
    var Server = Console.ReadLine();
    Console.WriteLine("Enter the Instance Name:");
    var instancename = Console.ReadLine();
    try
    {
        OdbcConnection DbConnection = new OdbcConnection("Driver= {Microsoft ODBC for Oracle};Server=" + Server + ":1521/" + instancename + ";Uid=system;Pwd=manager;");
        DbConnection.Open();
        DbConnection.Close();
        tw.WriteLine("No errors");
    }
    catch (Exception e)
    {
        tw.WriteLine(e);
    }
    finally
    {
        tw.Close();
    }
}

如果我从具有oracle服务器的计算机上运行这个小工具,它可以正常工作。我在其他几台服务器和具有oracle实例的计算机上测试它也可以正常工作。

我们发现在Windows Server 2012或窗口8上,连接无法打开。

当我在x86中编译我的应用程序时:

我收到此消息错误,与安装盾牌抛出的错误相同:

System.Data.Odbc.OdbcException (0x80131937): ERROR [NA000] [Microsoft][ODBC driver for Oracle][Oracle]Error while trying to retrieve text for error ORA-01019
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [01000] [Microsoft][ODBC Driver Manager] The driver doesn't support the version of ODBC behavior that the application requested (see SQLSetEnvAttr).
   at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
   at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
   at System.Data.Odbc.OdbcConnectionOpen..ctor(OdbcConnection outerConnection, OdbcConnectionString connectionOptions)
   at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.Odbc.OdbcConnection.Open()

当我在x64中编译它时,我收到一条不同的错误消息:

System.Data.Odbc.OdbcException (0x80131937): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
   at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
   at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
   at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.Odbc.OdbcConnection.Open()

任何提示?

我有一些丢失的dll吗?我在哪里可以下载它们?

1 个答案:

答案 0 :(得分:0)

根据此http://msdn.microsoft.com/en-us/library/ms713590%28v=vs.85%29.aspx“此功能将在未来的Windows版本中删除。请避免在新的开发工作中使用此功能,并计划修改当前使用此功能的应用程序。而是使用ODBC驱动程序由Oracle提供。“

我的建议是使用ODP.Net(它们有32位和64位驱动程序,可以同时安装) http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html