Server Reference In SQL Server 2005 Connection String

J

Joey

Hello all,

I develop on two or three different machines at different times. I need
a connection string in my app that will always reference the local
instance (for whatever machine) of Microsoft SQL Server 2005. I have
found that the following will work, but I have to change the machine
name as I code on each box...

"server=MACHINENAME;database=MYDATABASE;uid=sa;password=[somepassword];"

I know that I should be able to use a generic reference instead of the
actual machine name, as I used to do with SQL 2000, but it doesn't work
anymore now. I have tried...

"server=local;database=MYDATABASE;uid=sa;password=[somepassword];"
"server=(local);database=MYDATABASE;uid=sa;password=[somepassword];"
"server=localhost;database=MYDATABASE;uid=sa;password=[somepassword];"
"server=(localhost);database=MYDATABASE;uid=sa;password=[somepassword];"

....but the app times out and says "System.Data.SqlClient.SqlException:
SQL Server does not exist or access denied."

I also tried...

"server=127.0.0.1;database=MYDATABASE;uid=sa;password=[somepassword];"

....but then it times out and says "System.Data.SqlClient.SqlException:
General network error. Check your network documentation."

I installed Microsoft SQL Server 2005 Developer edition on these boxes.
I installed all of the default settings and did not create special
instance names or anything. Also, the server name (local) works fine
when logging into SQL Server Management Studio.

Any suggestions?
 
V

Virendra Chandra

hey man,
try it this.
"server=127.0.0.1;database=MYDATABASE;trusted_connection = yes";
it should work.
 
J

Joey

Thanks, but it didn't work. The following is what I used, copied and
pasted out of the Visual Studio 2005 IDE. I only changed the database
name and password...

"server=127.0.0.1;database=MYDATABASE;uid=sa;password=MYPASSWORD;trusted_connection=yes;"
 
J

Joey

Since it always wants the machine name (or presumably the IP address),
I thought about using Environment.MachineName in the connection string.
Worked like a charm.

#$#@#$@!$@#[email protected] didn't I think of this earlier?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top