简体   繁体   English

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

[英]Data source name not found, and no default driver specified

I need help fixing an error: SQL state IM014 in SQLConnect and SQL state IM002 in SQLConnect .我需要帮助修复错误: SQL state IM014 in SQLConnect SQL state IM002 in SQLConnect

I run the same script, one on webserver/remote/ and the other one from the local Machine trying to access the same database but i get different error message.我运行相同的脚本,一个在webserver/remote/ ,另一个从本地机器尝试访问相同的数据库,但我收到不同的错误消息。

When i run it from web server i get当我从网络服务器运行它时,我得到

SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQL SQL 错误:[unixODBC][驱动程序管理器]未找到数据源名称,且未指定默认驱动程序,SQL 中的 SQL 状态为 IM002

where as when i run it on local machine i get当我在本地机器上运行它时,我得到

[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application [Microsoft][ODBC 驱动程序管理器] 指定的 DSN 包含驱动程序和应用程序之间的体系结构不匹配

I used the following code in php script to connect to the Local database我在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

My ODBC.ini looks like below我的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

Very simple!很简单!

On server:在服务器上:

SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQL SQL 错误:[unixODBC][驱动程序管理器]未找到数据源名称,且未指定默认驱动程序,SQL 中的 SQL 状态为 IM002

Delete the USER data source name and define it as a SYSTEM data source name.删除 USER 数据源名称并将其定义为 SYSTEM 数据源名称。 Go to -> Start -> Settings -> Control Panel -> Administrative Tools -> Data Sources (ODBC): - User DSN : delete the specified User DSN - System DSN : create a new System DSN转到 -> 开始 -> 设置 -> 控制面板 -> 管理工具 -> 数据源 (ODBC): - 用户 DSN:删除指定的用户 DSN - 系统 DSN:创建新的系统 DSN

Else try to install same 32bits or 64bits version as locally installed.否则尝试安装与本地安装相同的 32 位或 64 位版本。

Locally:本地:

[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application [Microsoft][ODBC 驱动程序管理器] 指定的 DSN 包含驱动程序和应用程序之间的体系结构不匹配

32bit/64 bit conflict - either you install a 32bit driver version or you use/configure the 32bit under C:\\Windows\\SysWoW64\\ 32 位/64 位冲突 - 要么安装 32 位驱动程序版本,要么在 C:\\Windows\\SysWoW64\\ 下使用/配置 32 位

Try to install same 32bits or 64bits version as locally installed.尝试安装与本地安装相同的 32 位或 64 位版本。

There are a few things that can cause this.有一些事情可能会导致这种情况。 First, the DSN needs to be declared on both machines, on the remote machine it needs to be a WAN or LAN address depending on where it lives in the network.首先,需要在两台机器上声明 DSN,在远程机器上,它需要是 WAN 或 LAN 地址,具体取决于它在网络中的位置。 Second you need to make sure you have the right ODBC driver, there are 32 bit drivers and 64 bit drivers.其次,您需要确保拥有正确的 ODBC 驱动程序,有 32 位驱动程序和 64 位驱动程序。 MySQL connector ships with both. MySQL 连接器与两者一起提供。

32 bit ODBC: %systemdrive%\Windows\SysWoW64\odbcad32.exe
64 bit ODBC: %systemdrive%\Windows\system32\odbcad32.exe

I would try removing the 64 bit driver, adding the 32 bit driver and see how that goes.我会尝试删除 64 位驱动程序,添加 32 位驱动程序,看看效果如何。 Also, make sure you test your ODBC to make sure you have connection.此外,请确保您测试您的 ODBC 以确保您有连接。 If you after than then time to check the coding.如果您之后再检查编码。

First open the administrative tools option.首先打开管理工具选项。 Check your operating system.检查您的操作系统。 If you are using 64-bit then select driver of 64-bit.如果您使用的是 64 位,则选择 64 位驱动程序。 Or it is 32-bit then select 32-bit.或者它是 32 位然后选择 32 位。

Please do not make any user DSN.请不要制作任何用户DSN。 Select system DSN.选择系统 DSN。

eg I made System DSN which name is "empcon1" then in PHP code you should write like this:例如,我创建了名称为“empcon1”的 System DSN,然后在 PHP 代码中你应该这样写:

$dbNewName = "empcon1"; <br/>
$dbUserName = "yash"; <br/>
$dbPassword = "yash";<br/>
$conn=odbc_connect($dbNewName,$dbUserName,$dbPassword);

thats all.. You will get connected.仅此而已.. 您将获得连接。

In my case, I was trying to connect a PHP script to a MS Access 2003 database (.mdb file) using the code I found somewhere else:就我而言,我试图使用我在其他地方找到的代码将 PHP 脚本连接到 MS Access 2003 数据库(.mdb 文件):

$dbName = "C:\\DB\\myAccessFile.mdb";
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; charset=UTF-8; DBQ=$dbName; Uid=myUserName; Pwd=secret;");

// use the connection here
$result = $db->query('SELECT * FROM tableName');
$counter = 1;
while ($row = $result->fetch()) {
    echo $row["firstName"] . " " . $row['lastName'];
    echo '<br/>';
    $counter = $counter + 1;
    if ($counter == 50) {
       break;
    }
}

// and now we're done; close it
$sth = null;
$dbh = null;

Operating system: Windows 10 Pro.操作系统:Windows 10 专业版。

WAMP server version: 3.1.9 WAMP 服务器版本:3.1.9

Just make sure the driver specified in the code matches exactly the driver name in the ODBC dialog box, as shown in this image:只需确保代码中指定的驱动程序与 ODBC 对话框中的驱动程序名称完全匹配,如下图所示:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sqlsrv_connect:找不到数据源名称,并且未指定默认驱动程序 - sqlsrv_connect: Data source name not found and no default driver specified PDO_ODBC:找不到数据源名称,并且未指定默认驱动程序 - PDO_ODBC: Data source name not found and no default driver specified sqlsrv_connect:未找到数据源名称且未指定默认驱动程序 - sqlsrv_connect: Data source name not found and no default driver specified SQL错误:未找到数据源名称且未指定默认驱动程序 - SQL error: Data source name not found and no default driver specified PHP + odbc:找不到数据源名称,并且未指定默认驱动程序 - PHP + odbc: Data source name not found and no default driver specified 使用PHP连接到MS SQL数据库:找不到数据源名称,并且未指定默认驱动程序 - Connecting to MS SQL database with PHP: Data source name not found, and no default driver specified 警告:odbc_connect():SQL 错误:[Microsoft][ODBC 驱动程序管理器] 未找到数据源名称且未指定默认驱动程序 - Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified odbc_connect(): SQL 错误: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect - odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect isql 异常 unixODBC 数据源名称未找到 - isql exception unixODBC data source name not found 关于“找不到数据源名称”的建议解决方案不起作用 - Suggested solutions on “Data source name not found” not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM