Exception when connecting to MsSQL server


B

bg_ie

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.
 
Ad

Advertisements

S

sloan

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;Integrated
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.
 

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

Top