We have an app that uses a sqlexpress db. We need our customers to be able to swap the database for this app out for another sqlexpress db fairly easily. So we came up with a small launcher app that allows them to choose the db they want from a drop down list. It then detaches the current db and attaches the db that they chose and launches the program.

I tried to automate the set up of the multiple databases. Our process is to install the initial db and then detach and rename the .mdf and .ldf files. We then run our software and it gets a fresh copy of the db. So I added a new db button that when clicked does exactly that. In windows xp this works without problem. However in windows vista and 7 I get an exception that folder access is denied for renaming the .ldf file. The .mdf file renames without issue. I tried manually renaming the two files to see if it was a permissions issue with the DATA folder in sqlserver. With this test I found that I can simply right click and rename the .mdf file, but the .ldf causes the UAC prompt to come up so that I can grant it permission to be renamed.

I'm assuming that the UAC prompt is my problem but when I try to rename the file programmatically I do not get the prompt, just an exception.

What is the best way to deal with the UAC?

Thanks

You need to change the projects manifest file a bit.

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <applicationRequestMinimum>
        <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
        <defaultAssemblyRequest permissionSetReference="Custom" />
      </applicationRequestMinimum>
      <!-- Add these lines if missing, else change level from 'AsInvoker' to 'requireAdministrator' -->
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v2">
        <!-- UAC Manifest Options -->
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

Thank you for the reply. I tried this but received an error when I went to publish. I'm deploying as a clickonce app and it says that:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

is not available for clickonce deployment. Is there something else I need to do along with this?

This question has already been answered. Start a new discussion instead.