在某些平台上使用 odbc 时出错(32 位与 64 位)
本文关键字:出错 位与 odbc 平台 | 更新日期: 2023-09-27 18:34:28
我们正在使用 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
或
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 服务器 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吗?我在哪里可以下载它们?
根据此 http://msdn.microsoft.com/en-us/library/ms713590%28v=vs.85%29.aspx"此功能将在将来版本的Windows中删除。避免在新的开发工作中使用此功能,并计划修改当前使用此功能的应用程序。请改用 Oracle 提供的 ODBC 驱动程序。
我的建议是使用 ODP.Net(它们有 32 位和 64 位驱动程序,可以同时安装两者(http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html