I have installed Xampp with php 5.3.5 on a (64bit) Windows and I want to connect to a Database using a 3rd party ODBC driver in a (32bit) SQL Server 2005 but it always bring the same mistake "SQL error: Data source name not found and no default driver specified”. I have created a System DSN and I try to connect using an odbc_connect. I will truly greatly appreciate any help.
-
Please provide the code you're using to connect (obfuscate sensitive data, of course).Matt– Matt2012-08-01 19:42:22 +00:00Commented Aug 1, 2012 at 19:42
-
so the code I am using for the connection is $con = odbc_pconnect("Driver={drivername}; server='servername'; dsn='dsnname';", "", ""); if (!$con) {exit("Connection Failed: " . $con);} I am pretty new to these things as you can see but I really want to learn. So, thanks a lot for your replyI Y– I Y2012-08-02 10:08:45 +00:00Commented Aug 2, 2012 at 10:08
4 Answers
There are 2 ODBC driver managers on Windows 64 bit. I suspect you've used the wrong one. You need to find out whether your xampp is 32 bit or 64 bit then you need to define the DSN in the right ODBC Administrator. See 64-bit ODBC, it explains it all in a lot of detail.
3 Comments
We have found that the issue is typically with sqlncli.dll not registering properly for some reason. It is either going to be because of an issue with the dll file itself, permissions to the registry, etc.
Here's how we have come to resolve this error:
Open Regedit
Navigate to H_KEY_LOCAL_MACHINE\Software\ODBC\ODBCINST
NOTE: If it is a 64 bit computer and you are working with a 32-bit SQL install, the path will probably actually be H_KEY_LOCAL_MACHINE\Software\WOW6432Node\ODBC\ODBCINST
In the ODBCINST key, verify that the SQL Native Clent regkey exists. Click on it and verify that the all of the values for it populate on the right side of the screen. It should read something like:
(Default) REG_SZ (value not set)
APILevel REG_SZ 2
Connectfunctions REG_SZ YYY
CPTimeout REG_SZ 60
Driver REG_SZ c:\windows\system32\slncli.dll
DriverODBCVer REG_SZ 09.00
FileUsage REG_SZ 0
Setup REG_SZ c:\Windows\System32\sqlncli.dll
SQLLevel REG_SZ 1
Usagecount REG_DWORD 0x00000001 (1)
If all you see is the (Default) entry, slncli.dll did not register properly, meaning that the SQL Native Client ODBC Driver is not properly registered.
Proceed as follows:
Ensure you are logged in as an administrator. Give the currently logged in user full control permissions to the regkey. Note that you may have to take ownership of the key to be able to set permissions to it. There are plenty of resources that describe how to take ownership of a regkey and set permissions to it, so I won't go into detail here about that.
Once you have full control permissions to the key, the Values may simply appear on the right-hand side of the screen. This means it was simply a permissions issue.
If the values still don't appear, your next step will be to verify that sqlncli.dll is present in the Windows\System32 folder or Windows\SysWow64 folder (for 64 bit systems). If it is not present, you will have to obtain a copy from another PC, ensure the PC you retrieve it from has the same OS as the one that is missing the file.
If the file is present, check the version of the file. SQL 2005 uses version 9.00.4035.00. If no version is listed for the file, it is corrupt and again, you will want to pull a copy from another PC.
If the file is present and a version is listed, manually register it from a command line using regsvr32.
Comments
I just spent half a day with this very issue and finally figured it out - for my situation at least. I know this thread is a bit old, but it was relevant nonetheless.
You need to make sure the version of osql.exe matches the version of native client that you're using. I had osql.exe from 2005 and native client from 2008 R2. As soon as I used the '08 R2 osql.exe everything worked as expected.