蘋果瓶子

Hello :

My application needs to attach one MS access DB for datastorage.

I adopt following code (c#):

----------------------------------------------------------------------------------------------------

public string GetDBConnStr()
{

string DBLocation = string.Concat(Application.StartupPath, "\\Data", "\\NTUStuAPPDB.mdb");
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBLocation + ";Persist Security Info=True";
return ConnStr;
}

-------------------------------------------------------------------------------------------------

to get Deploy DB location.

It works fine in windows MSI installation but get trouble in clickone deploy.

When client runs the application deployed by clickone the application shows error message "can not find DB location".

I open the application installed location and find that there are two locations clickonce installed the application

in client machine.

1.C:\Users\Daniel\AppData\Local\Apps\2.0\TCMG9NA0.0NG\AT9CWEZ4.EQH\ntus...exe_c9c6df7d908bab6f_0001.0000_none_218803baf6b66815

(which contains Data folder and correct database)

2.C:\Users\Daniel\AppData\Local\Apps\2.0\TCMG9NA0.0NG\AT9CWEZ4.EQH\ntus..tion_c9c6df7d908bab6f_0001.0000_d066d02b40ead0aa

(which folder install everything excepts data folder)

It seems "Application.StartupPath" code only get above item 2 path hence that can not find my deploy DB.

Could someone help me to solve this issue

Any suggestions will be very appreciated.

Sincerely,

Daniel Lee 2007/9/16



Re: ClickOnce and Setup & Deployment Projects How to deploy database in clickone ?

Ken_L

From solution explorer,

right click on your database

Click on properties

under the copy to output directory property, change it from do not copy to copy always or copy if newer






Re: ClickOnce and Setup & Deployment Projects How to deploy database in clickone ?

Shyam Vaidya

Hello,

Please try using assembly path.Follwing is VB Code...

Dim DBLocation As String = System.Reflection.Assembly.GetExecutingAssembly().Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\"))

use this DBLocation variable as path of DB.

I am not sure but try...

Thanks & Regards.






Re: ClickOnce and Setup & Deployment Projects How to deploy database in clickone ?

Elizabeth Maher - MSFT

Daniel,

I am assuming that your database file is marked as a 'Data File'. (See the Application Files dialog off the Publish Property Page.) All files marked as Data Files will be put into a special Data Folder by the ClickOnce runtime. To access this folder use ApplicationDeployment.DataFolder (http://msdn2.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.datadirectory.aspx).

Regards,

Elizabeth Maher

VB Team






Re: ClickOnce and Setup & Deployment Projects How to deploy database in clickone ?

Yu Guo – MSFT

Hi, Daniel,

Based on my understanding, you cannot access to the Access File while using ClickOnce deployment, right

I think this issue is caused by the connection string.

And Elizabeth Maher's answer could work after you deploy your project with ClickOnce.

However, I think a more general way is to change the DBLocation with this code.

Code Snippet
string DBLocation = string.Concat("|DataDirectory|", "\\Data", "\\NTUStuAPPDB.mdb");

Here DataDirectory means the ClickOnce DataDirectory,

it's where you found the Acess File in your computer.

And this solution also works in a Setup Project.

More info about ClickOnce Data Directory

http://msdn2.microsoft.com/en-us/library/d8saf4wy.aspx

Hope this helps,

Regards






Re: ClickOnce and Setup & Deployment Projects How to deploy database in clickone ?

蘋果瓶子

Thanks Yu Guo and Elizabeth Maher both methods work for me.

It helps me to solve the problem





Re: ClickOnce and Setup & Deployment Projects How to deploy database in clickone ?

Imomin

Here is another problem, I have 3 crystal reports .rpt files. Its properties are Build Action = Embedded Resource, Copy to Output Direct = Copy Always etc... But, after the depoyment when I run the reports in the application it gives me File Load error.