Solved

Why doesn't my connection work?

Posted on 2014-01-30
4
285 Views
Last Modified: 2014-01-31
I've got a SQL Server Studio installed with a quality connection to the database.

I've got an ODBC connection running happily that connects to the database named symbion_bgust.

The code on my page is:

<?php

$cxn=odbc_connect('symbion_bgust');
if(!$cxn)
{
echo "you're still not connected.";
}

Current landscape: My ODBC Connection was a bear getting to work. It wasn't until I used a Named Pipes configuration and made my database the default database. Only then was I able to get past all of the "tests" successfully.

When I go out to IIS Manager and click on "Database Manager" and double click on "Local SQL Server" I get an error that reads:

"An attempt to attach an auto-named database for file C:\Windows\system32\inetsrv\aspnetdb.mdf filed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."

Don't know if that's a factor, but the convoluted mess that I've had to contend with coupled with my ignorance has made for a very frustrating several hours.

Why am I not able to use a seemingly healthy ODBC connection and connect to my SQL Server?
0
Comment
Question by:brucegust
  • 2
4 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 39822115
"Why am I not able to use a seemingly healthy ODBC connection and connect to my SQL Server? "


Did you created a ODBC data source on that server with all the details? like server name/IP, database name, login, password? You need that to be created and tested to make sure you can connect to that server/database before using it in the code.
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39822128
I have never before been able to connect with PHP to an SQL Server database by using anything but a TCP/IP connection.  Microsoft SQL Server has more settings than MySQL does and is a little more difficult to get working.

But I messed around with a test program and got it working.  A note on this page http://us1.php.net/manual/en/function.odbc-connect.php about it requiring a System DSN instead of a User DSN was the last clue.  This is the format that worked where $odbcName is the name of a System DSN on your computer.
// System DSN version
$conn = odbc_connect($odbcName,$dbuser, $dbpass) or die ("Could not connect to server");

// DSN-less version that I have also used
$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$serverName;Database=$dbname;", $dbuser, $dbpass);

Open in new window

0
 

Author Comment

by:brucegust
ID: 39824460
Perfect!

Thanks, Dave!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39824764
You're welcome.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now