By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

Server Reference In SQL Server 2005 Connection String

P: n/a
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;pas sword=[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;passw ord=[somepassword];"
"server=(local);database=MYDATABASE;uid=sa;passwor d=[somepassword];"
"server=localhost;database=MYDATABASE;uid=sa;passw ord=[somepassword];"
"server=(localhost);database=MYDATABASE;uid=sa;pas sword=[somepassword];"

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

I also tried...

"server=;database=MYDATABASE;uid=sa;passw ord=[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?

Jan 12 '06 #1
Share this Question
Share on Google+
3 Replies

P: n/a
hey man,
try it this.
"server=;database=MYDATABASE;trusted_conn ection = yes";
it should work.
Jan 12 '06 #2

P: n/a
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=;database=MYDATABASE;uid=sa;passw ord=MYPASSWORD;trusted_connection=yes;"

Jan 12 '06 #3

P: n/a
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.

#$#@#$@!$@#$@....Why didn't I think of this earlier?

Jan 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.