Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please tell me why I failed with this should I do then?

  • local machine name = MYPC
  • local instance name = MSSQLSERVER
  • my own database named mydatabase
  • I use Windows authentication to log into the local server, username = DOMAIN\mypc
  • I have no password when I log into the local server;

Lines I used are here:

$connection= new-object
$Connection.ConnectionString ="server=MSSQLSERVER;database=mydatabase;trusted_connection=false;uid=DOMAIN\mypc;"

These lines failed with the following error:

Exception calling "Open" with "0" argument(s): "A network-related or
instance-specific error occurred while establishing a connection to SQL Server.
The server was not found or was not accessible. Verify that the instance name is
correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
At line:1 char:17
+ $ <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
share|improve this question
up vote 1 down vote accepted

A see a few problems with our connection string:

MSSQLSERVER is usually the service name for a default instance of SQL Server in which case you would use "server=MYPC" or you can use dot for the local machine "server=.". If you really have an instance name of MSSQLServer which is doubtful then your server you be "server=.\MSSQLSERVER"

When using Windows authentication i.e. trusted_connection you don't specify a uid and trusted_connection should be set to true. Here's what your connection should look like:

$Connection.ConnectionString ="server=.;database=mydatabase;trusted_connection=true;"
share|improve this answer
Thank you very much! I stucked here for 2 days! – pansal Jul 6 '11 at 2:18
If you could mark question as answered--thanks – Chad Miller Jul 6 '11 at 19:14
Of course~ I marked your answer now :) – pansal Jul 8 '11 at 5:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.