简体   繁体   English

如何使我的安装项目在Winform应用程序中包含数据库(.sdf)文件?

[英]How Do I make my Setup Project Include my Database (.sdf) file along with the winform application?

I have created a Winforms application in VS 10 (C#), with SQL Server Compact Edition 3.5 as a back end. 我已经在VS 10(C#)中创建了Winforms应用程序,并以SQL Server Compact Edition 3.5作为后端。

First I created a new setup project by following these steps. 首先,按照以下步骤创建一个新的安装项目。

But I got database file could not be found exception on installing application on client's machine. 但是我发现在客户端计算机上安装应用程序时找不到数据库文件异常。

Then I tried creating a setup project and included my database (.sdf) file in Application Folder and I got following exception: 然后,我尝试创建一个安装项目,并将我的数据库(.sdf)文件包含在“ 应用程序文件夹”中,并且出现以下异常:

Internal error: Cannot open the shared memory region. 内部错误:无法打开共享内存区域。

I am getting the database file by following code : 我通过以下代码获取数据库文件:

SqlCeConnection con = new SqlCeConnection("DataSource=|DataDirectory|\\myDatabase.sdf");

And my DataDirectory is pointing to the path 而且我的DataDirectory指向path

string path = AppDomain.CurrentDomain.BaseDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);

Can anyone please help me including my database file? 谁能帮我包括我的数据库文件吗?

Add the database file to your applications folder in your setup. 将数据库文件添加到设置中的应用程序文件夹中。

Then in your connection use 然后在您的连接中使用

SqlCeConnection con = new SqlCeConnection("DataSource=myDatabase.sdf");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#:在安装项目中创建.exe时,如何包括.sdf数据库文件和Crystal Reports? - C# : how to include .sdf database file and Crystal Reports while creating .exe in setup project? 如何使我的 winform 项目可共享? (如何将数据库设置为项目文件夹?) - How can i make my winform project shareable? (how can i set the database to the project folder?) 如何运行该数据库备份并从Winform应用程序还原脚本? - How do I run that database backup and restore scripts from my winform application? 如何重新启动我的 C# WinForm 应用程序? - How do I restart my C# WinForm Application? 当winform应用程序关闭时,如何停止线程 - How do I stop a thread when my winform application closes 如何使用C#连接到Winform应用程序中的.sdf文件? - How to connect to .sdf file in Winform application using C#? 如何使用Winform应用程序从Outlook中打开文件附件? - How do I open a file attachment from Outlook with my winform application? 如何在C#中连接到.sdf本地数据库文件 - How do I connect to a .sdf local database file in C# 如何在我的安装项目中包括点混淆输出? - How to include dotfuscated output in my setup project? 如何在我的安装项目中包括vlc安装? - How to include a vlc installation in my setup project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM