Clickonce deployment - An attempt to attach an auto-named database failed

Hi,

I have an application which I wish to deploy using clickonce from a web server to a number of client machines using VS 2005 Beta 2. The application requires an SQL Server Express instance on client machines to manipulate user data.

When I publish my application to an apache web server the client machine is able to install the application with no problems. However whenever the application is loaded on the client machine I get the exception "An attempt to attach an auto-named database failed....". This exception does not occur in normal debugging.

It appears that it is trying to access a database file copied over to the client machine during the installation process in the directory: ...Local Settings/Apps/Data/WDWJC...etc. On examination of the specified folder the .mdf file exists. Also:,

-SQL server express is installed on the client machine
-The "User Instance" parameter of database's connection string is set to "true"
-In the project properties page the dataset and corresponding database files are included in the "Application Files..." on the project publish tab.

Can anyone help me with this problem? I have included the error log on the end of this thread.

Best Regards,
Duncan

System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:\Documents and Settings\enpdrc\Local Settings\Apps\Data\WDWJC29J.RZZ\1C13621C.9DV\cifl..tion_213110b321431b25_0001.0000_dd7859fb985de49f\Data\ciflex.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at WindowsApplication1.Form1.LoadWatchers()
at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at WindowsApplication1.ciflex.Components.HotKey.HotKeyForm.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

[4464 byte] By [DuncanR.Campbell] at [2008-2-8]
# 1
Hi Duncan,

There are a couple of things that could cause this. The most common cause of this is that the .mdf file is not where the connection string is pointing. Here are some things you can do to diagnose the problem:

1. Add some debugging code to your app to see the full path to the Data directory. The full path returned by DataDirectory + everything after the string "|DataDirectory|" in your connection string should match the location of the file on disk. The code would be something like this:

MsgBox(System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory)

2. You can check to see if there is already an instance of the database attached to SQL Express. To do this, you can download the SSEUtil tool at http://www.microsoft.com/downloads/details.aspx?FamilyID=FA87E828-173F-472E-A85C-27ED01CF6B02&displaylang=en. Once you have the tool installed on the client machine, run SSEUtil.exe -L to see if there is already an instance of your database attached. If there is, then you can detach it by running SSEUtil.exe -D <YourInstanceName>.

If you are still seeing this problem after trying these things, you can post back here and I will try to help you further.

Jay Hickerson
Visual Basic Team

JayHickerson at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic IDE...
# 2

Hi Jay

I'm getting this error too but under different circumstances. I'm extending the moviecollection starter kit. The kit uses a database containing a DVD table which contains the details of each movie. I've add 3 lookup tables to the database. On startup the app opens the database and fills up the DVD table. This works fine. I've added code to fill up the other three tables. This is where I'm encountering the problem. Here's the code:

Dim i, j, k, l, m As Integer


i = Me.DVDsTableAdapter.Fill(Me.DVDCollectionDataSet.DVDs)<== this works

j= Me.GenreTableAdapter.Fill(Me.DVDCollectionDataSet.Genre) <== fails here

...

If there was a problem with a conflicting instance, you'd think it should have complained on the first Fill stmt.

If I comment out the 3 Fill stmt for the tables I've added, the app runs fine.

Any idea why I'm getting this problem?

Your help is greatly appreciated.

Gary

garyf at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic IDE...
# 3

I figured it out. The stmt

i = Me.DVDsTableAdapter.Fill(Me.DVDCollectionDataSet.DVDs)<== this works

must have been pointing to the local database and

j= Me.GenreTableAdapter.Fill(Me.DVDCollectionDataSet.Genre) <== fails here

must have been pointing to the database in the \bin\debug directory.

Once I wired things the right way everything worked fine.

Gary

garyf at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic IDE...