Вопрос

PDO is beginning to get me down. My php code keeps falling over at this line :-

$conn = new PDO('sqlsrv:server=127.0.0.1,1000;Database=Database.mdf', 'root', '');

and I have no idea why. It generates the following error message....

Uncaught exception 'PDOException' with message 'SQLSTATE[08001]: 
[Microsoft][SQL Server Native Client 11.0]TCP Provider: Timeout error [258]. ' in 
E:\Website\DataValidation.php:5

Seem to be spending all my time trying to connect to a database before I can even start using the data inside.

FYI, I have tried with and without the ".mdf", as well as with and with the port at the end of the IP address.

Это было полезно?

Решение

$conn = new PDO(
          'sqlsrv:server=(localdb)\v11.0;AttachDBFileName=c:\db.MDF','root', '');

If necessary, you can create a LocalDB instance with sqllocaldb.exe. You can also use sqlcmd.exe to add and modify databases in a LocalDB instance. For example:

 sqlcmd -S (localdb)\v11.0. 

You shouldn't have to specify the Database name, but if you want to:

$conn = new PDO( 
     'sqlsrv:server=(localdb)\v11.0;AttachDBFileName=c:\db.MDF;Database=myDb',
     'root', '');
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top