468,554 Members | 1,896 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

Exception when connecting to MsSQL server

Hi,

I like to develope an application which uses a MsSQL database. I
believe that C# works really well with MsSQL. To start with, I'd like
to host the sql server locally on my machine as I develop, but later
I'd like to be able to host it on a server and have multiple instances
of the application access the server.
I have installed SQL Server 2005 Express Edition on my machine but was
never prompted for a user name or anything like that. I attempt to
connect to the server using -

SqlConnection myConn = new SqlConnection("Server=localhost;Integrated
security=SSPI;database=master");

But I get an exception:
ServerVersion 'myConn.ServerVersion' threw an exception of type
'System.InvalidOperationException' string
{System.InvalidOperationException}
base {"Invalid operation. The connection is closed."}
System.SystemException {System.InvalidOperationException}

Can anyone explain to my what is wrong. Perhaps I have to configure
the installation of SQL Server but I'm not sure.

Thanks,

Barry.

Mar 7 '07 #1
1 12638

Usually, when the express edition is installed, you have an "Instance" name.

so localhost would be wrong in this scenario.

Try:
SqlConnection myConn = new
SqlConnection("Server=mymachinename\SqlExpress;Int egrated
security=SSPI;database=master");
Or do a google search for how the sqlexpress edition connection string is
formed.

...

The reason? InstanceNames allow more than 1 version (or instance) of sql
server to be installed on the same computer, thus you need a way to
differeniate them.


<bg***@yahoo.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
Hi,

I like to develope an application which uses a MsSQL database. I
believe that C# works really well with MsSQL. To start with, I'd like
to host the sql server locally on my machine as I develop, but later
I'd like to be able to host it on a server and have multiple instances
of the application access the server.
I have installed SQL Server 2005 Express Edition on my machine but was
never prompted for a user name or anything like that. I attempt to
connect to the server using -

SqlConnection myConn = new SqlConnection("Server=localhost;Integrated
security=SSPI;database=master");

But I get an exception:
ServerVersion 'myConn.ServerVersion' threw an exception of type
'System.InvalidOperationException' string
{System.InvalidOperationException}
base {"Invalid operation. The connection is closed."}
System.SystemException {System.InvalidOperationException}

Can anyone explain to my what is wrong. Perhaps I have to configure
the installation of SQL Server but I'm not sure.

Thanks,

Barry.

Mar 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by stefanPL | last post: by
2 posts views Thread by Richard Collette | last post: by
9 posts views Thread by Advo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.