DataDirectory Set up project

I am doing a SETUP project for a C# winforms, sqlite application. Connection string seems to a bit of a problem. The user will put the Database he wants to work with at a location(which v will tell him). In this example it is "C:\\Program Files(x86)\\DefaultCompany\\RSetup"; The user can work his own copy of the DB.

So I am setting the data directory to this path in the Program.cs Main This is the only way I can think of. If there is a better way thats grt!!.

 App.config 

        <add name="ConnString" connectionString="|DataDirectory|\MySQlite.db;Compress=True;Version=3"
              providerName="System.Data.Sqlite" />

  Program.cs 
    Setting the datadirectory to the path of the executable. Currently hard coded the path of the executable 
      static void Main()
            {

                   AppDomain.CurrentDomain.SetData("DataDirectory","C:\\Program Files(x86)\\DefaultCompany\\RSetup");

This doesn't seem to be working. It doesn't give any error except the data is not blank. Doesn't seem to be working in both set up and the regular project

Thank you JC

Answers


You could ask the user where the database is located, store that path somewhere (such as User Settings) and then you can retrieve it at any time. This would give the user more flexibility of where to put it and multiple users on the same machine could have their own database if desired.

Here is some pseudocode...

string dbLocation = Properties.Settings.Default.DatabaseLocation;
if (string.IsNullOrWhiteSpace(dbLocation)
{
    dbLocation = AskUserForLocation();
    Properties.Settings.Default.DatabaseLocation = dbLocation;
    Properties.Settings.Default.Save();
}

AppDomain.CurrentDomain.SetData("DataDirectory",dbLocation);

Using this approach you could also add a menu option to allow the user to change the location if desired.

It also gives you the ability to retrieve the value anywhere, including where you create a connection, you can append the path to the location between where you read the connection string and you create a new connection.

SQLiteConnection myConnection = new SQLiteConnection;();
myConnection.ConnectionString = Path.Combine(Properties.Settings.Default.DatabaseLocation, myConnectionString);
myConnection.Open();

Need Your Help

When i change @SessionScoped to @ViewScoped i always got JDOM exception

jsf session-scope view-scope

i want to change the scope of one jsf page @SessionScoped to @ViewScoped but i always got this exception and i dont understand why.

AJAX and HTML element not working

javascript jquery html ajax getelementbyid

I am trying to set a div tag to display a message if user isn't found in the database.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.