connection string with AttachDBFileName=... doesn't work

R

R.A.M.

Hello,
I am writing ASP.NET application using SQL Server 2005 Express Edition.
In web.config I have:

<connectionStrings>
<add name="MIM-Magazyn_Demo"
connectionString="Server=.\SQLEXPRESS;AttachDBFileName=|DataDirectory|\MIM-Magazyn_Demo.mdf;Database=MIM-Magazyn_Demo;Trusted_Connection=Yes"
providerName="System.Data.SqlClient"/>

<add name="SqlServices"
connectionString="Server=.\SQLEXPRESS;AttachDBFileName=|DataDirectory|\aspnetdb.mdf;Database=aspnetdb;Trusted_Connection=Yes"/>

</connectionStrings>

I used connection strings syntax from www.connectionstrings.com. I decided
to use AttachDBFileName because I don't expect that application user will
have both databases attached in SQL Server Management Studio.

The problem is that during execution, in a line:

Membership mu = Membership.GetUser();

I receive System.Data.SqlClient.SqlException
{"Cannot create file
'F:\\Inetpub\\wwwroot\\MIM-Magazyn\\App_Data\\aspnetdb_log.LDF' because it
already exists. Change the file path or the file name, and retry the
operation.\r\nCould not open new database 'aspnetdb'. CREATE DATABASE is
aborted.\r\nCould not attach file
'F:\\Inetpub\\wwwroot\\MIM-Magazyn\\App_Data\\aspnetdb.mdf' as database
'aspnetdb'.\r\nFile activation failure. The physical file name
\"F:\\inetpub\\wwwroot\\MIMMagazyn\\App_Data\\aspnetdb_log.LDF\" may be
incorrect."}

Could you help me please to solve the problem?
Thank you!!!
/RAM/
 
G

Guest

Membership data is stored in this database 'aspnetdb'. if this db does not
exists
it automatically creates one, so it you don;t have it , it will create one 4
you.

also lets rule out permissions issue, check if folder has R/W permission.

Regards
JIGNESH
 
R

R.A.M.

U¿ytkownik "JIGNESH said:
Membership data is stored in this database 'aspnetdb'. if this db does not
exists
it automatically creates one, so it you don;t have it , it will create one
4
you.
I have it created.
also lets rule out permissions issue, check if folder has R/W permission.
I have R/W permission.
 
N

Norman Yuan

Please study a bit more on SQL Server Express "User Instance" and
"AttachDBFileName". If you have created the database for your ASP.NET 2.0
website, there is not need to use "User Instance" and attaching DB file each
time a request is sent to the website.

I am sick of all entry level .NET books showing code examples using SQL
Server Express user instance/AttachDBFile to newbies without whole chapter
to explain the special User Instance clearly.This has confused so many
newbies. Just see how many questions are related to this in various NGs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top