[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • 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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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