Nete​​zza公司读取数据​​库表从C#通过ODBC不工作在Windows 7数据、工作、公司、Nete

2023-09-03 02:17:36 作者:倚栏清风

为什么不能.NET通过安装{NetezzaSQL}驱动程序连接到我的Netezza公司中? 64位应用程序也无法通过这个ODBC连接连接。为什么会是这样?我已经建立了控制面板中的用户和系统的Net​​ezza ODBC连接,都做工精细,当我点击测试连接?我看到在注册表中的值,但是当我穿越注册表驱动程序,.NET并没有看到NetezzaSQL。据Netezza公司,他们没有一个64位ODBC驱动程序。他们提供的驱动程序应该为32位和64位应用程序。难道这是一个权限问题可能与Windows 7?

Why can't .NET connect to my Netezza box via the installed {NetezzaSQL} driver? 64bit applications also cannot connect via this ODBC connection. Why would that be? I've built both user and system Netezza ODBC connections in Control Panel, and both work fine when I click "Test Connection"? I see the value in the registry, but when I traverse the registry drivers, .NET does not see "NetezzaSQL". According to Netezza, they don't have a 64 bit ODBC driver. The driver they provide should work for 32 and 64 bit applications. Could this be a permissions issue perhaps with Windows 7?

static void CreateNetezzaTableObjectFolders()
{
    //string activeDir = @"C:\Source\EDW\dw-objects\trunk";

    OdbcConnection conn = new OdbcConnection();
    conn.ConnectionString = "Driver={NetezzaSQL};servername=10.1.170.18;port=5480;database=DEV_SANDBOX; username=mac;password=secret;";

    OdbcDataReader rdr = null;

    try
    {
        conn.Open();
        System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand("SELECT OBJECT_NAME FROM QA_ETL..STG_OBJECTS", conn);
        rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            Console.WriteLine(rdr[0]);
            // Create Folder
            //string objectName = rdr[0].ToString();
            //string newPath = System.IO.Path.Combine(activeDir, objectName);
            //System.IO.Directory.CreateDirectory(newPath);
        }
    }
    finally
    {
        // close the reader
        if (rdr != null)
        {
            rdr.Close();
        }

        // close the connection
        if (conn != null)
        {
            conn.Close();
        }
    }
}

打开新的标签,查看注册表设置的ODBC和放大:

============================

============================

显然,驱动程序名称那张大括号内。当我的驱动程序列表编程,我没有看到司机。我如何添加到这个列表中的Windows用户界面?我不过,看到在控制面板中安装了Netezza公司的驱动程序>管理工具> ODBC驱动程序。

Apparently, the driver name goes inside of the curly brackets. When I get a list of drivers programmatically, I don't see the driver. How do I add to this list in the Windows user interface? I do however, see the installed Netezza driver under the Control Panel > Administrative Tools > ODBC Drivers.

下面是一些code,验证我所解释:

Here is some code that verifies what I am explaining:

public static void GetSystemDriverList()
{
    //List<string> names = new List<string>();
    // get system dsn's
    Microsoft.Win32.RegistryKey reg = (Microsoft.Win32.Registry.LocalMachine).OpenSubKey("Software");
    if (reg != null)
    {
        reg = reg.OpenSubKey("ODBC");
        if (reg != null)
        {
            reg = reg.OpenSubKey("ODBCINST.INI");
            if (reg != null)
            {

                reg = reg.OpenSubKey("ODBC Drivers");
                if (reg != null)
                {
                    // Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
                    foreach (string sName in reg.GetValueNames())
                    {
                        Console.WriteLine(sName);
                        //names.Add(sName);
                    }
                }
                try
                {
                    reg.Close();
                }
                catch { /* ignore this exception if we couldn't close */ }
            }
        }
    }

    Console.ReadLine();
}    

下面是连接错误,我从微软从Windows 7中访问2007年获得当我使用的用户ODBC连接。系统中的一个是不可见的。

Here is the connection error I get from Microsoft Access 2007 from the Windows 7 box when I use the user ODBC connection. The system one was not visible.

错误:ODBC - 调用失败[微软] [ODBC驱动程序管理器]指定的DSN包含了驱动程序和应用程序之间的结构不匹配(#0)

Error: "ODBC--call failed. [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application (#0)"

推荐答案

微软从未更名为他们的SYSTEM32文件夹,所以SYSTEM32真的有所有的64位驱动程序。而SysWow64文件夹拥有所有的32位驱动程序。默认情况下,在Visual Studio 2010中创建一个.NET项目将有86的目标平台。我只是改变了它的x64和我联系工作,让我的64位NetezzaSQL驱动程序工作.NET。

Microsoft never renamed their "system32" folder, so system32 really has all of the 64 bit drivers. And SysWow64 folder has all of the 32 bit drivers. By default, a .NET project created in Visual Studio 2010 will have a "Target Platform" of x86. I just changed it to x64 and my connection worked to get my 64 bit NetezzaSQL driver working for .NET.

只是意识到,你可以通过在不管是C运行odbcad32.exe的文件启动ODBC(数据源)控制面板下的对话框>管理工具:\ WINDOWS \ SYSTEM32 \文件夹(这是64位版本对话框打造64位驱动程序),或在C:\ WINDOWS \ SysWow64文件\文件夹(这是对话的32位/ x86版本打造32位驱动程序)。是的,这些文件夹是相反的,因为微软是怪异的方式。

Just realize that you can launch the ODBC (Data Sources) dialog under Control Panel > Administrative Tools by running the "odbcad32.exe" file in either the C:\Windows\system32\ folder (this is the 64 bit version of the dialog to build 64 bit drivers), or in the C:\Windows\SysWow64\ folder (this is the 32 bit/x86 version of the dialog to build 32 bit drivers). Yes, the folders are reversed because Microsoft is weird that way.

此外,还有在得到建注册表两个不同的文件夹。原来,上面的列表(在我黑色的屏幕截图)来自计算机\ HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ ODBC \列表,因为这些都是32位驱动程序。我安装,nzodbcsetup.exe的DLL,显然是安装为64位驱动程序。我不完全知道如何安装这个在64位Windows 32位驱动程序,所以这就是为什么我在.NET项目从默认的86到64改变了目标平台。必须有一种方法来安装它作为一个32位的驱动程序,以及因为当我在32位Windows XP中安装此,驾驶员精细的工作。

Furthermore, there are two different folders in the Registry that get built. Turns out that the list above (in my black screen shot) comes from the Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ list because those are 32 bit drivers. The dll I installed, "nzodbcsetup.exe", apparently installed as a 64 bit driver. I am not exactly sure how to install this as a 32 bit driver on 64 bit windows, so that's why I changed the "Target Platform" in my .NET project from the default x86 to x64. There has to be a way to install it as a 32 bit driver as well because when I installed this on a 32 bit Windows XP box, the driver worked fine.

有什么奇怪的是,Netezza的OLE驱动程序是分开的。他们有一个32位和64位的DLL exe文件(适用于6.0.3版)。 nzoledbsetup.exe(82MB〜86)和nzoledbsetup64.exe(102MB〜64位)。但ODBC只是有一个,这显然是两者。我试图手动生成32位驱动程序在SysWOW6432Node(下运行>注册表编辑器),并指出该驱动程序文件和设置文件(在system32文件夹,但我得到了一个错误,请发表评论,有没有办法在Windows自动安装为32位,而不是64。

What's weird is that Netezza's OLE drivers are separated. They have a 32 bit and a 64 bit dll exe file (for version 6.0.3). "nzoledbsetup.exe" (~82MB x86) and "nzoledbsetup64.exe" (~102MB x64). But the ODBC just has one, which is apparently both. I tried manually building a 32 bit driver in the SysWOW6432Node (under run > regedit) and pointed to the Driver file and Setup file (in the system32 folder, but I got an error. Please comment is there a way in Windows to automatically install as 32 bit, not 64.