Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > ClickOnce SQL Server 2005 Database Attach Fails
 

ClickOnce SQL Server 2005 Database Attach Fails

Hi All,

I am building a VS2005 Database project, and I have recently discovered the use of ClickOnce apps. However I have a problem that I don't understand.

I have a SQL Server 2005 DB, marked "SQL Server 2005 Express" as a prerequisite, so that's OK.
I had trouble with the connection string, but I found in another thread that ClickOnce copies the MDF file to a Data folder, and that the connectionstring can be made as follows:

Initial Catalog=<appname>; Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\<dbname>.mdf;Integrated Security=True

So that should be OK too. When I deploy it, the app is installed in C:\Documents and Settings\Wouter\Local Settings\Apps\2.0\<something>\<something else>\...

So far so well, then when the app is ran, and the connection is opened, i get the following error:

Directory lookup for the file "Settings\Wouter\Local Settings\Apps\2.0\Data\<something>\<something else>\...\<appname>.mdf" failed with the operating system error 5(Access is denied.)."
Could not attach file '........... <again the same>' as database '<dbname>'.

This led to much frustration, searched all over the net, and nobody seems to have had the same error.

In a bright moment I set the Permissions for the SQL Server User account ('BLUEBIRD-X2\SQLServer2005MSSQLUser$BLUEBIRD-X2$SQLEXPRESS' to be precise) to Full on the Local Settings folder (right click > properties > security), and then IT WORKED.

Now the question: WHY is this necessary? I suppose a ClickOnce app has full security permissions on its install directory?
I cannot expect all end users to set the permissions on the Local Settings folder, especially because it is hidden.
How can I make my database connect to this *hidden & secured* path, that i cannot change due to ClickOnce default install path?

If i remove the Security Permissions for the SQL Server User account, after the DB has been attached to SQL sever, then connecting is again no problem.

Any answer is welcome.

Thank you,

Wouter

PS. I am not using < > in my db name , just indicating variables

Wouter1986  Monday, November 27, 2006 12:27 PM

Have you given "FullTrust" to your Click Once application? You will be able to give this when you create the manifests using mage.exe or mageui.exe

Cheers

Mohan

moGun  Monday, November 27, 2006 11:32 PM

You can use google to search for other answers

Custom Search

More Threads

• VB program with setup solution, assigning icon to outputted exe
• Strange ClickOnce window messes up VS
• Windows Service Not Stopping Before Upgrade
• Windows Installer concept - self updating program
• Multiple executables delivered through 1 ClickOnce?
• shortcut creation error!
• ClickOnce for Sub Main Application
• SETUP WIZARD USING MSCMS.LIB ONLY WORKS FOR XP AND NOT FOR VISTA
• ClickOnce and Declarative CAS - any point ?
• Insert product key to setup(.exe) file