Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why doesn't my connection work?

Posted on 2014-01-30
4
Medium Priority
?
298 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 40

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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

Expert Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

963 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