Code Project

Link Unit

Friday, June 27, 2008

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 locate

I was implementing the sample given at this site http://www.beansoftware.com/ASP.NET-Tutorials/Web-Parts.aspx and encountered the issue.
An attempt to attach an auto-named database for file c:\.....\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.
The solution for which is as follows:
we have to add following few lines to the web.config file as below:

"User Instance=True;"
Once I added this option to the Connection String everything works fine. So the new connectionstrings look like this.

<connectionstrings>
<remove name="LocalSqlServer">
<add name="LocalSqlServer" providername="System.Data.SqlClient" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=DataDirectory\ASPNETDB.MDF;user instance=true;Integrated Security=True;Initial Catalog=ASPNETDB;">
</connectionstrings>

I hope this helps the visitors.

Tuesday, June 03, 2008

Using DBMS_METADATA.GET_DDL to generate the table script

I was using Oracle 10g where it required to get the Scripts of all the tables.
While searching google I ended up with DBMS_METADATA.GET_DDL

SELECT DBMS_METADATA.GET_DDL ('TABLE',tname)';' FROM tab where tabtype='TABLE'

I hope this help the visitors.