views:

161

answers:

4

I am setting up a membership provider, and as a result, I am getting the following error message:

An attempt to attach an auto-named database for file

C:\Users\Mcoroklo\Desktop\Programmering\Private Projekter\ASP.NET\Helpdesk\Version4\HelpDesk\ClientSite\App_Data\ASPNETDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I am new to setting up membership so I can't deny something really crucial is missing! :-)

I am quite sure this has something to do with my connection string and/or SQL Membership provider. I've the following setup in my web.config:

My connection string:

  <connectionStrings>
<add name="MembershipServer" connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf; Trusted_Connection=Yes;"/>

My SQL provider

 <membership defaultProvider="AspNetSqlProvider">
  <providers>
    <clear/>
    <add connectionStringName="MembershipServer" 
         name="AspNetSqlProvider"
         applicationName="/" 
         type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </providers>
</membership>

My authentication and authorization:

 <authentication mode="Forms">

  <forms name=".ASPXFORMSAUTH" loginUrl="Site/Login.aspx"
      cookieless="UseCookies"  >
  </forms>
</authentication>

<authorization>
  <deny users="?"/>
</authorization>

The file structure in my website is I've two local databases in my directory. The membership one (ASPNETDB.MDF) is the one i point at with my connection string. I've used the ASP.NET tool to create it.

The other database I connect to via LINQ TO SQL classes and is in a different project (using tier layers).

Thanks a bunch!!

A: 

Try removing the \ before the database name.

AttachDbFilename=|DataDirectory|ASPNETDB.mdf

instead of:

AttachDbFilename=|DataDirectory|\ASPNETDB.mdf

Oh and another thought, you do have SQL Express loaded on the machine, correct?

Brettski
A: 

Thanks for answering.

It didn't do anything, sadly.. Same error message.

(edit: Same user as thread poster.. New on site so was a bit confused about open id)

Mcoroklo
add this as a comment. Do post your reply as an "answer"
Shoban
What is this in reference to?
Brettski
+1  A: 

Visual Studio will initialize all of that for you. You are getting in it's way. It has yet to create and provision that database for you.

Delete the connection strings element, the membership element, the authentication element and the authorization element.

or better yet Start with a fresh Asp.Net Application

Then click Project(or website)> Asp.net Configuration and follow the steps.

otherwise you will need to create and provision your own db with aspnet_reqsql.exe.

Sky Sanders
A: 

Remember that machine.config defines a Connection String with the name "LocalSqlServer" and by default your app will use that.

To fix the problem, either explicitly remove the name like this:

<connectionStrings>
    <remove name="LocalSqlServer" />
    <!-- your new connection string here -->
</connectionStrings>

or use clear, but I haven't tested it:

<clear/>

Usually what I do is just overwrite the LocalSqlServer, so my connection string is named the same, that seems to fix most problems.

Like others have mentioned, you are attaching the ASPNETDB when it should do that for you when you setup your app using the ASP.NET Site Manager.

subkamran