Solved

Why doesn't my connection work?

Posted on 2014-01-30
4
288 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 83

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 83

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

10 Experts available now in Live!

Get 1:1 Help Now