• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

Attaching to a SQL Express db using the connection string

does anybody has experience in attaching a .mdf sql express db file using the connection string ?

I am trying a thing as so:

<add key="CONNECTION_STRING" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|file_path|\mydbname.MDF;Integrated Security=True;Initial Catalog=mydbname;" />

but I am unable to connect.

I am using asp.net 1.1

Any help is veeery welcome because it is urgent!
Regards

Davide
0
NetDeveloper
Asked:
NetDeveloper
  • 3
  • 2
1 Solution
 
GavinMannionCommented:
Try dropping the AttachDbFilename, also add the userid and password. Add in a DataBase key as well
0
 
NetDeveloperAuthor Commented:
Hi GavinMannion, tnx for ur Reply...u say to remove AttachDbFilename ? but at the provider I do not have the db restore...I just have that file.
0
 
GavinMannionCommented:
Hmm sorry I was not paying full attention...

taken from http://www.connectionstrings.com/

#   Attach a database file on connect to a local SQL Server Express instance:
"Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Database=dbname;Trusted_Connection=Yes;"
   - or -
"Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
   (use |DataDirectory| when your database file resides in the data directory)

    Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection).

0
 
NetDeveloperAuthor Commented:
Hi, I get the error:

System.Exception: Unable to get connection.General network error. Check your network documentation
0
 
GavinMannionCommented:
Can you access the SQLExpress database using the SQl Server Managment tool on that server?

Possibly the SQL server is rejecting incoming connections?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now