views:

81

answers:

2

I have an ASP.NET web application build using VWD 2008 and using SQL Server Express. When I start my application from within VWD 2008 (i.e., using the ASP.NET development server), it works fine. However, when I close VWD 2008 and try to load the application using IIS 5.1, it fails with this error:

An attempt to attach an auto-named database for file failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Here is my connection string:

<add name="Version013ConnectionString"
     connectionString="Data Source=.\SQLEXPRESS;
     AttachDbFilename=&quot;C:\MyFilepath\App Name\App_Data\Version013a.mdf&quot;
     Integrated Security=True;Connect Timeout=30;
     User Instance=True" providerName="System.Data.SqlClient"/>

I'm aware that this issue crops up quite regularly on the forums - I've spent quite a while reading them and trying different ideas, with no success.

As I say, I don't understand why it works under ASP.NET dev server but not under IIS. My guess is there's some sort of permissions issue, but that's just a guess and I'm open to any suggestions.

TIA,

Paul

A: 

Any chance this has something to do with permissions? This may be the difference between your credentials and the ASPNET account.

David Andres
I think it probably is a permissions issue. The trouble is, I have a very poor grasp of how Windows permissions work.Are you saying that my account (i.e. me, the current logged on user) may have different permissions from ASPNET? How would I check this?
PaulH
Go into your IIS Virtual Directory properties for this website, and click on the Directory Security tab. Verify whether anonymous access is checked. If it is, then IIS will use an IUSR account and possibly ASPNET to access resources. You'll know this is a problem if you uncheck Anonymous Access, fire up your page again, and the attachment works fine. In that case, IIS is using your own credentials to access the file. In that case, be sure to add the IUSR* account and ASPNET to the folder in which the database resides.
David Andres
No joy, I'm afraid. I unchecked Anonymous Access, and found that I couldn't access my site at all - all I got was a standard Windows error message "You are not authorized to view this page".
PaulH
Check Integrated Windows Authentication in Directory Security and see if that buys you anything.
David Andres
No, that didn't do the trick either I'm afraid.
PaulH
Stealing this off of this forum post: http://forums.asp.net/t/879454.aspx. Can you add "User Instance=True;" to your connection string?
David Andres
Ah - "User Instance = true" is already in the connection string.
PaulH
I retried your suggestion about checking Integrated Windows Authentication. This time it did make a difference (must've done something wrong last night - late, tired). The difference is that now the css is getting loaded, so at least the home page looks ok. This was not happening before, so that's progress. However, the database problem hasn't gone away.
PaulH
PROBLEM SOLVED! It turns out I'd left out the phrase "Initial Catalog = dbname" from the connection string. This guy explains it pretty well: http://manfredlange.blogspot.com/2007/06/attempt-to-attach-auto-named-database.html#comment-form. Thanks very much to David Andres for input and solving the css issue. If you're ever in Bath, UK, I'll buy you a beer :-)
PaulH
Ha, great! Never been to Britain...
David Andres
A: 

Just to clarify (more for my own benefit than anyone else's, I suspect):

  • I created a db using SQL Server Express.

    I put it in the app_data folder of my asp.net application.

    I point to it using the connection string shown above.

    I start the app from VWD 2008, everything works fine.

    I start the app directly from the browser using localhost, and I get the database error described above.

The only difference is that I'm using two different servers, so it has to be down to permissions, doesn't it?

PaulH