Hi again.

I am on the part where I am ready to publish my .cs program and tried to install it to my friends pc when I noticed it doesnt connect to the sql and just makes an error, I noticed that i declared all my paths like this:
Sample 1.)

String path=("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Justine\\Documents\\Visual Studio 2010\\Projects\\CAPSTONE\\CAPSTONE\\CoffeeShopDatabase.mdf;Integrated Security=True;User Instance=True");

Sample 2.)

string fileName = "C:\\Users\\Justine\\Documents\\Visual Studio 2010\\Projects\\CAPSTONE\\CAPSTONE\\drawerport.txt";

what should be my approach so that I can install it to other pc.

thanks

Edited 2 Years Ago by pritaeas: Added markdown.

You can try something like this Article usually it would be better to host the database in a central location instead of user pc's. Or just use plain windows authentication. In your case you would need to display this screen on startup initially when the application first runs on a new client pc and then configure the connection and save the string.

Unfortunately this example is in VB but you can easily modify it and use it in your C# application as the namespaces would be the same.

Another example Link

Edited 2 Years Ago by Fenrir()

How bout putting the database file into the same directory as your .exe file? Then, instead of using absolute path, you can do something like this:

String path=("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CoffeeShopDatabase.mdf;Integrated Security=True;User Instance=True");

The |DataDirectory| directory automatically detects the current path of your .exe file. With that you could put the database to the same directory.

How bout putting the database file into the same directory as your .exe file?

That's risky. If the application isn't run with administrative rights, extraneous files may not be accessible if they're in the application folder. A better approach would be to use something like Environment.SpecialFolder.CommonApplicationData and storing the paths/connection strings in a configuration file.

Typically anything that depends on the environment should be configurable anyway. Hard coded paths are a big no-no unless they're guaranteed to be legit and accessible across the board, which is difficult to do.

try ruuning application as admin and see if the problem persists

here's the code for the manifest file for admin privileges

<?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">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

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

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
      <applicationRequestMinimum>
        <defaultAssemblyRequest permissionSetReference="Custom" />
        <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
      </applicationRequestMinimum>
    </security>
  </trustInfo>
</asmv1:assembly>
This article has been dead for over six months. Start a new discussion instead.