How can I correct this error: Data source name not found and no default driver specified

a 夏天 提交于 2019-12-11 04:58:49

问题


I have a website that runs in Windows server, and it works perfectly fine. I tried to make a copy in my localhost but I get the error:

Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\xampp\htdocs\tdms\webfolders\secured\db_fns.php on line 29
 Could not connect to database server

line 29 contains:

function fgsdb_connect()
{

   $a=array();
   $retvar=0;

   $result = odbc_connect('FGS','tdms','tdms358',SQL_CUR_USE_ODBC); //---->line 29

   if (!$result) // cannot establish connection to database

     throw new Exception('Could not connect to database server');

   else // connection to database has been established

     return $result;

}

I am really new to odbc. the website is written in php and the database that i use in mySQL. though i figured that the database that it is trying to connect is a microsoft access MDE file. (i checked in the site in windows server.) What should i do? im sorry but i am really


回答1:


It's likely the shortcut for setting ODBC data sources is pointing to the 32bit data sources instead of 64bit.

Go to control panel -> administrative tools --> select data sources(ODBC) --> then right click on that file --> go to properties --> in the shortcut tab -> change the path from

%windir%\System32\odbcad32.exe

to

%windir%\SysWOW64\odbcad32.exe

and make your connection. the driver for MS Access will work fine now.

If it doesnt work, try to connect to the ODBC with a sentence like this:

$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\YourFolder\YourFile.mdb",'Youruser', 'YourPassword');

The last 2 leave then just the the '' if you dont have any user or password




回答2:


I was getting the same error on PHP 7.0.8 64bit while trying to connect to an Access .mdb.

I had to do two things:

  1. Install the 64bit version of "Microsoft Access Database Engine 2010 Redistributable" (even with Access 2016 installed I was getting your error). You can download the driver from:

    https://www.microsoft.com/en-us/download/details.aspx?id=13255

    Then, if you go to the ODBC Data Source Administrator, you should notice the 64bit version.

  2. Change the driver string to:

    Driver={Microsoft Access Driver (*.mdb, *.accdb)}

Hope it helps other people.



来源:https://stackoverflow.com/questions/9122611/how-can-i-correct-this-error-data-source-name-not-found-and-no-default-driver-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!