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.

2
edit delete
are you sure?
asked Hussain

1 answer

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

Integrated security=true;

and

Trusted_Connection=Yes;

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

http://www.connectionstrings.com/sqlconnection/attach-a-database-file-on-connect-to-a-local-sql-server-express-instance/

That's probably the cause of your error.

1
edit delete
are you sure?
answered Max Wikström

Post an answer but please log in first

Post Answer
  1. Please log in to post answer

Similar Questions

Tagsfor this question

Forumall questions