发布Windows窗体项目 [英] Publish a windows form project

查看:66
本文介绍了发布Windows窗体项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想将Windows窗体项目发布到应用程序(.exe).我使用了project->属性->发布.有一个数据库也应该发布.

我的代码是:

OleDbConnection cn = new OleDbConnection("Provider=''Microsoft.Jet.OLEDB.4.0'';Data Source=|DataDirectory|\\data\\jamiyi.mdb;");
            OleDbDataAdapter adp = new OleDbDataAdapter();
            OleDbCommand cmd = new OleDbCommand();
            DataSet tb = new DataSet();
            try
            {
                cn.Open();
                MessageBox.Show("Connection Open ! ");
                cn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not open connection ! ");
            }


问题是当我运行项目时,与数据库的连接打开,但是当我发布项目时,连接失败(我运行发布的项目的另一台具有所有程序要求的PC).


那我该怎么做才能解决?

在此先谢谢您.添加了您的主要输出.


尝试以管理员身份运行.

也许检查出异常.

MessageBox.Show("Can not open connection ! " + ex.Message);


Hello,

I want to publish a windows form project to an application (.exe) . I used project->properties->publish. there is a database which should published also.

my code is:

OleDbConnection cn = new OleDbConnection("Provider=''Microsoft.Jet.OLEDB.4.0'';Data Source=|DataDirectory|\\data\\jamiyi.mdb;");
            OleDbDataAdapter adp = new OleDbDataAdapter();
            OleDbCommand cmd = new OleDbCommand();
            DataSet tb = new DataSet();
            try
            {
                cn.Open();
                MessageBox.Show("Connection Open ! ");
                cn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not open connection ! ");
            }


the problem is when I run the project the connection to the database opens but when I publish the project the connection fails(I run the published project another PC which has all program requirements).


so what I have to do to fix it?

Thanks in advance.

解决方案

First of all try to create a setup file this would help you, Now you have to add your .mdb file at same folder where you have added your Primary output.


Try running as administrator.

And maybe check out the exception.

MessageBox.Show("Can not open connection ! " + ex.Message);


这篇关于发布Windows窗体项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆