Solved

Why doesn't my connection work?

Posted on 2014-01-30
4
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

752 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