Sql connection string error, connection is aborted

I am creating a windows application.using sql server 2008.
I am getting connection string problem while connecting to .mdf file which is in this location c\folder\file.mdf.
first of all I have created 1 database in the sql with the tables. now I de-attached it. from c:\program files\sql server\data\mydb.mdf&mydb_log.ldf, I copied in desktop. now from my application when ever I am entering a text and then click create button event it ic creating a texbox1.text.mdf and textbox1_log.ldf. now I want to connect to this created database file.

I have give like this connection string but it is giving me connection is aborted and so on.

SqlConnection con = new SqlConnection(@"Data Source=.\SQLExpress;Integrated security=true;AttachDbFilename=c:\maq\" + textbox1.Text                                             +  ".mdf;Trusted_Connection=Yes");

Help me for this
I did this using .mdb it is successful but sql giving me trouble. I am new to use sql if I did any mistake please let me know I want learn a lot.

1 answer

I'm not sure if this is the cause of your error but specifying booth

Integrated security=true;



is redundant. They do the same (make use of windows authentication). Try remove one of them.

You should also specify a database name in your connection string as in here


That's probably the cause of your error.