Monday, March 26, 2012

How to fix SQLExpress "attempt to attach an auto-named database" e

I'm authoring a .net webservice that connects to a SQLExpress database in the
same project. When the code calls the database the following exception is
thrown:
"An attempt to attach an auto-named database for file
C:\[...]\App_Data\App_Data\MyDatabase.mdf failed. A database with the same
name exists, or specified file cannot be opened, or it is located on UNC
share."
I've read all the online help I can find but none of the suggestions work.
* I've deleted the SQLExpress folder in my ApplicationData
* I've made sure to enable user instances in the server and RECONFIGURE
* I've restarted the service
* I've ensured that ASPNET and NETWORK SERVICE has rights to the APP_DATA
folder.
Nothing changes. What is the cause of this issue' How can I fix it'
Thanks,
JasonSolved.
It took finally writing this post to see that the rendered connection string
renders "APP_DATA" twice.
This is how the project defaults - I didn't do that. Screw them.
Jason
"Jason" wrote:
> I'm authoring a .net webservice that connects to a SQLExpress database in the
> same project. When the code calls the database the following exception is
> thrown:
> "An attempt to attach an auto-named database for file
> C:\[...]\App_Data\App_Data\MyDatabase.mdf failed. A database with the same
> name exists, or specified file cannot be opened, or it is located on UNC
> share."
> I've read all the online help I can find but none of the suggestions work.
> * I've deleted the SQLExpress folder in my ApplicationData
> * I've made sure to enable user instances in the server and RECONFIGURE
> * I've restarted the service
> * I've ensured that ASPNET and NETWORK SERVICE has rights to the APP_DATA
> folder.
> Nothing changes. What is the cause of this issue' How can I fix it'
> Thanks,
> Jason|||Congratulations!
Have a great day!
Charles Wang
Microsoft Online Community Support|||But it still doesn't work right. After the change, it will not have that
error in run-time, but now it won't work in design-time. The DataSet
visualizer can't find the datasource from the given connectionString.
This is using the Application project template for WebService and not the
Website template. That may be part of the problem.
Jason
"Charles Wang[MSFT]" wrote:
> Congratulations!
> Have a great day!
> Charles Wang
> Microsoft Online Community Support
>|||Hi Jason,
Thanks for your response.
I recommend that you try to connect the SQL Server Express on other clients
via SQL Query Analyzer or other SQL client tools. If you manage to access
the server, this issue is most likely caused by some settings in your
Webservice IDE (vs.net 2005?). You can post this issue to .net public
community for best support.
Also, for now, I recommend that you check your connection string, by
default the SQLExpress instance name should be set to "<server
name>\SQLEXPRESS".
You may want these references:
http://blog.davebouwman.net/2006/03/27/SQLExpressConnectionProblems.aspx
http://msdn.microsoft.com/vbrun/vbfusion/usingsqlexpress/
http://www.connectionstrings.com/
Charles Wang
Microsoft Online Community Support|||Hi ,
Just checking in to see if the suggestions were helpful. Please let us know
if you would like further assistance.
Have a great day!
Charles Wang
Microsoft Online Community Support|||Charles,
Thanks, but no. Those suggestions seem to address a different issue. I
think what's happening here is that when using the non-website project
template for ASP.Net Webservice (downloaded from Microsoft's site) the
connection string contains an extra "APP_DATA" directory literal.
At design time, this is the correct setting and the dataset designers can
find and connect to the database correctly, but at runtime the "APP_DATA"
literal is /extra/ because the "|DataDirectory|" placeholder is resolved
differently to already include the APP_DATA folder.
I'm posting these findings to save others from frustration, but I've in fact
changed direction.
Jason
"Charles Wang[MSFT]" wrote:
> Hi ,
> Just checking in to see if the suggestions were helpful. Please let us know
> if you would like further assistance.
> Have a great day!
> Charles Wang
> Microsoft Online Community Support
>|||Hi Jason,
Appreciate your posting here for having others benefit from this issue.
My former reply may not understand your issue clearly. I thought it was
just a normal SQL Server break/fix issue on connection.
This issue is most likely a .net development issue.I recommend that you
post this issue to public .net newsgroups for best professional support.
If you also want to get support on this newsgroup, I would like to get a
simple project example from you so that I can try to reproduce this issue
for further research.
Sincerely yours,
Charles Wang
Microsoft Online Community Support|||I just had the same problem. I noticed that Permissions on APP_DATA
were not being inherited by the .mdf and .ldf files. Made sure ASPNET
had permission to folder then changed to inherit permissions and all
works OK. Don't know security issues but this is a development site so
don't care.

No comments:

Post a Comment