Solved

Why doesn't my connection work?

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

863 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

24 Experts available now in Live!

Get 1:1 Help Now