Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DSN-Less Connection String to MSSQL DB

Status
Not open for further replies.

MikeBronner

Programmer
Joined
May 9, 2001
Messages
756
Location
US
Hi there,

What I am looking for is pretty specific: a dsn-less connection string to a mssql database. I have all ther pertinent information, however, I can't get it to work. For hypothetical purposes, I am using the following information:

Driver: SQL Server
Server: mssql.host.com
Database: TestDB
User: MyUser
Password: MyPass

What I'm using right now looks like this:

$dsn = 'driver=SQL Server;server=mssql.host.com;database=TestDB;uid=MyUser;pwd=MyPass;';
$dbh = DBI->connect("dbi:ODBC:$dsn") or die DBI->errstr;

However, when I execute this, I get a 'silent' failure; the scripts stops without any error message and worst of all without connecting. Can anyone point out what I am doing wrong?

Thanks! Take Care,
Mike
 
Here's a simple method that I use when I can't remember the syntax:

Open Windows Notepad. Without entering anything, click File/Save. Change the save type to "All Files" and name the file XXXX.udl -- where XXXX is any name you wish. Close Notepad. Right-click the file XXXX.udl and choose properties. Go through the steps of configuring a connection, then choose OK. Open the XXXX.udl file in Notepad again and copy the contents of the file. Parse out the extra spaces that it adds and you have a valid connection string that you can paste anywhere.
 
Just a shot in the dark, I don't know what you are connecting from, but have you tried $dsn = Driver = SQL Server ?

I use VB for a front end and my connection string looks like this:

cn.connectionstring = "Driver=SQL Server;uid=MyUser;pwd=MyPass;Server=mssql.host.com;database=testDB"

Rob
Just my $.02.
 
CCTC1,

That's pretty kewl. I didn't try it until after I opened my mouth above. That's a hot for anyone I would think

Rob
Just my $.02.
 
Thanks guys ;-)

In VB I can connect without a problem, as well as in ASP.
I guess I'll have to resort to creating an ASP script. Take Care,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top