Unable to connect to database server

I am having a problem connecting to the database. I started with a new blank solution, then added a WCF library project, and finally, last but not least, a WCF website (service). On the website, I added a link to the library where I have an interface (data contract), a class that implements the interface and dataclasses. I am trying to connect to a database on a server and try to get some data from there. Therefore, the connection string looks like this:

<add name="myConnectionString" connectionString="Data Source=MyServer; Initial Catalog=MyDatabase; User Id=me; Password=me123;" providerName="System.Data.SqlClient" /> 

and this is how I try to connect to the database:

  public List<string> GetEngagements(string id) { string sql = "SELECT myColumn FROM myTable WHERE Id = '" + id + "'"; string connString = string.Empty; SqlConnection connDB; connString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString; connDB = new SqlConnection(connString); SqlCommand command = new SqlCommand(sql, connDB); connDB.Open(); SqlDataReader rdr = command.ExecuteReader(); List<string> numbers = new List<string>(); while (rdr.Read()) { numbers.Add(rdr[0].ToString()); } rdr.Close(); return numbers; } 

I get an exception in connDB.Open (). Then the exception message says: SQL Server user instance could not be created due to a failure in starting the process for the user instance. The connection will be closed.

I get this message for 2 days, I searched a lot and deleted the directory C: \ Documents and Settings \ username \ Local Settings \ Application Data \ Microsoft \ Microsoft SQL Server \ SQLEXPRESS, but it does not work for me ..

Any solution ???? help me please

+4
source share
1 answer

Error message:

The SQL Server user instance could not be created due to a failure in starting the process for the user instance.

It is assumed that you are using custom instancing, and therefore your connection string will point to the .mdf file on disk, not the database name.

So, I assume that you want to connect to the file instance, not the server instance.

I also assume that you are using SqlExpress and not the full version.

In this case, your connection string is incorrect. It should look like this:

 "Data Source=.\SQLEXPRESS; AttachDbFilename=fileOnDisk.mdf; Integrated Security=True; User Instance=True;" 

A user run means that this server instance and internal database will be visible only when the connection string is opened.

You do not need to use custom instancing - you can set User Instance=False or just leave it. Then, as soon as the application establishes a connection, you can connect other tools to the server instance and connect to the database yourself.

+2
source

All Articles