Server Reference In SQL Server 2005 Connection String

  • Thread starter Thread starter Joey
  • Start date Start date
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?
 
hey man,
try it this.
"server=127.0.0.1;database=MYDATABASE;trusted_connection = yes";
it should work.
 
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;"
 
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?
 
Back
Top