c# - Can't connect to database server -


i'm encountering problem database connection. started new blank solution, added wcf library project, , last not least wcf website (service). in website added reference library have interface (data contract), class implements interface , dataclasses. i'm trying connect database on server , try retrieve data there. connection string looks like:

    <add name="myconnectionstring" connectionstring="data source=myserver; initial catalog=mydatabase; user id=me; password=me123;" providername="system.data.sqlclient" /> 

and how i'm trying connect database:

    public list<string> getengagements(string id)     {         string sql = "select mycolumn mytable 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'm getting exception on conndb.open(). exception message says: failed generate user instance of sql server due failure in starting process user instance. connection closed.

i've been getting message 2 days now, i've googled lot , deleted c:\documents , settings\username\local settings\application data\microsoft\microsoft sql server data\sqlexpress directory didn't work me..

any solution???? please

the error message:

failed generate user instance of sql server due failure in starting process user instance.

suggests you're using user instancing, , therefore connection string point .mdf file on disk rather name of database.

so i'll assume want connect file instance rather server instance.

i'll assume you're using sqlexpress rather full fat version.

in case connection string wrong. should more this:

"data source=.\sqlexpress;  attachdbfilename=fileondisk.mdf;  integrated security=true;  user instance=true;" 

user instancing means server instance , db inside visible application opening connection string.

you don't have use user instancing - can set user instance=false or leave out. once application has made connection can connect other tools server instance , connect db yourself.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -