未找到数据源名称,并且未指定默认驱动程序

Kin*_*nfe 16 php sql sql-server odbc

我需要帮助修复错误:SQL state IM014 in SQLConnectSQL state IM002 in SQLConnect.

我运行相同的脚本,一个打开webserver/remote/,另一个从本地计算机尝试访问同一个数据库,但我得到不同的错误消息.

当我从网络服务器运行它我得到

SQL错误:[unixODBC] [驱动程序管理器]未找到数据源名称,并且未指定默认驱动程序,SQL中的SQL状态IM002

当我在本地机器上运行时,我得到了

[Microsoft] [ODBC驱动程序管理器]指定的DSN包含驱动程序和应用程序之间的体系结构不匹配

我在php脚本中使用以下代码连接到本地数据库

$odbc['dsn'] = "SageLine50v19";
$odbc['user'] = "Peac";
$odbc['pass'] = "XXXX";
$mysql['host'] = "localhost";
$mysql['user'] = "root";
$mysql['pass'] = "";
$mysql['dbname'] = "sagetest";
$mysql['idfield'] = "id";


// Step 1: Connect to the source ODBC database
if ($debug) echo "Connect to " . $odbc['dsn'] . ' as ' . $odbc['user'] . "\n";
$conn = odbc_connect($odbc['dsn'], $odbc['user'], $odbc['pass']);
if (!$conn) {
die("Error connecting to the ODBC database: " . odbc_errormsg());
}

// loop through each table 
$allTables = odbc_tables($conn);
$tablesArray = array();
while (odbc_fetch_row($allTables)) {
 if (odbc_result($allTables, "TABLE_TYPE") == "TABLE") {
    $tablesArray[] = odbc_result($allTables, "TABLE_NAME");
 }
}
 //print_r($tablesArray);      // to list all tables
Run Code Online (Sandbox Code Playgroud)

我的ODBC.ini如下所示

[ODBC 32 bit Data Sources]
manager=Sage Line 50 v16 (32 bit)
t=SQL Server Native Client 10.0 (32 bit)
s1=Pervasive ODBC Client Interface (32 bit)
SageLine50v19=Pervasive ODBC Client Interface (32 bit)
[manager]
Driver32=C:\Windows\SysWOW64\S16DBC32.dll
[t]
Driver32=C:\Windows\system32\sqlncli10.dll
[s1]
Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll
[SageLine50v19]
Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll
Run Code Online (Sandbox Code Playgroud)

小智 1

有一些因素可能会导致这种情况。首先,需要在两台计算机上声明 DSN,在远程计算机上,它需要是 WAN 或 LAN 地址,具体取决于它在网络中的位置。其次,您需要确保拥有正确的 ODBC 驱动程序,有 32 位驱动程序和 64 位驱动程序。MySQL 连接器随两者一起提供。

32 bit ODBC: %systemdrive%\Windows\SysWoW64\odbcad32.exe
64 bit ODBC: %systemdrive%\Windows\system32\odbcad32.exe
Run Code Online (Sandbox Code Playgroud)

我会尝试删除 64 位驱动程序,添加 32 位驱动程序,看看效果如何。另外,请确保测试 ODBC 以确保已建立连接。如果您之后有时间检查编码。