Connecting Tech Pros Worldwide Forums | Help | Site Map

visual c# project .exe and database problem

Member
 
Join Date: Nov 2008
Posts: 46
#1: Dec 3 '08
hallo everyone,

I have created a project in visual c# and a database with access 2007 .accdb. Now if i want to run the executable file (i mean .exe) in the bin should i also carry the database, if so will it connect to the database automatically or even if the create a DSN and when i run the .exe in the another computer the database connection string will differ. so what can be done ?.. any idea ?... help me please if anyone knows how to do it ..

Thank you,
Dinesh.

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Dec 3 '08

re: visual c# project .exe and database problem


It depends on how you connected to your database in your program...

Did you use an absolute path? The better way is to use one of the application variables that hold the path information.

If this is a Forms app, you can get the startup directory by using Application.StartupPath. Or you can get the app data path by using Application.UserAppDataPath.

What you should consider doing is adding an installer project to the solution, and adding both the project output and the database file. Have them both installed to the same directory, and use the Application.StartupPath to help build your connection string.
Member
 
Join Date: Nov 2008
Posts: 58
#3: Dec 7 '08

re: visual c# project .exe and database problem


Quote:

Originally Posted by insertAlias View Post

It depends on how you connected to your database in your program...

Did you use an absolute path? The better way is to use one of the application variables that hold the path information.

If this is a Forms app, you can get the startup directory by using Application.StartupPath. Or you can get the app data path by using Application.UserAppDataPath.

What you should consider doing is adding an installer project to the solution, and adding both the project output and the database file. Have them both installed to the same directory, and use the Application.StartupPath to help build your connection string.

You can also use App.config file to hold the connection string information.
You can define it <Connectionstring> entry in it.
Member
 
Join Date: Nov 2008
Posts: 46
#4: Jan 17 '09

re: visual c# project .exe and database problem


hello insertalias,

Its a form application, can u tell how can create a installer project ?...

Thank you.

Regards,
Dinesh.
Quote:

Originally Posted by insertAlias View Post

It depends on how you connected to your database in your program...

Did you use an absolute path? The better way is to use one of the application variables that hold the path information.

If this is a Forms app, you can get the startup directory by using Application.StartupPath. Or you can get the app data path by using Application.UserAppDataPath.

What you should consider doing is adding an installer project to the solution, and adding both the project output and the database file. Have them both installed to the same directory, and use the Application.StartupPath to help build your connection string.

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#5: Jan 17 '09

re: visual c# project .exe and database problem


If you are using the full version of Visual Studio (not Express) then one of the project types (under "Other Project Types -> Setup and Deployment") is a Setup Project. Add one of these projects to your current solution. You should be able to find some tutorials on the web on how to use this project type.
Member
 
Join Date: Nov 2008
Posts: 46
#6: Jan 17 '09

re: visual c# project .exe and database problem


hello insertalias,

i found how to create a installer project but should i create a application folder installer project and then add the database file to the folder and set the connection string as application.startuppath or application.userappdatapath to get the database work with the application ?. IS it enough if the add the database file by right clicking the application folder and click add and the click and file and add the database file ?...

Thank you.

regards,
Dinesh.

Quote:

Originally Posted by insertAlias View Post

If you are using the full version of Visual Studio (not Express) then one of the project types (under "Other Project Types -> Setup and Deployment") is a Setup Project. Add one of these projects to your current solution. You should be able to find some tutorials on the web on how to use this project type.

Reply