简体   繁体   English

C#项目-InstallShield,安装后运行时出现MySql错误

[英]C# Project - InstallShield , MySql error when run after installation

I have a project in C# which is created in Visual Studio 2013. I want to create an installer using Install Shield free version. 我在Visual Studio 2013中创建的C#中有一个项目。我想使用Install Shield free版本创建安装程序。 I created an installer and trying to run it on other computer but, when I run it and trying to log into program, I have problems about mysql database. 我创建了一个安装程序并尝试在其他计算机上运行它,但是当我运行它并尝试登录程序时,我遇到了有关mysql数据库的问题。 Error message is: 错误消息是:

Unhandled exception has occured in you application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.

Cannot connect.

If I click on details button, I have a serie of errors which refers on Mysql. 如果我单击“详细信息”按钮,则表示在Mysql上存在一系列错误。 Example: 例:

System.Exception: Cannot connect ---> MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at simulator.ConnConfig.getConnection()

simulator is the name of the project. simulator是项目的名称。 ConnConfig is a class where is the connection and getConnection() is a function from ConnConfig which return connection. ConnConfig是一个类,其中是连接,而getConnection()ConnConfig中的一个函数,该函数返回连接。 II tried to install on another computer .NET Framework 4.5.2, SQL Server, but also didn't worked. II试图在另一台计算机上安装.NET Framework 4.5.2 SQL Server,但也没有成功。 In my project, I use localhost server where I have a database with 2 tables. 在我的项目中,我使用localhost服务器,其中有一个包含2个表的数据库。 My question is, is there any possibility to add that localhost database to installer and use it on another computer? 我的问题是,是否有可能将本地数据库添加到安装程序并在另一台计算机上使用它? And what redistributables requires this operation? 哪些可再发行产品需要此操作? Also, I have installed on computer .NET Framework 4.5, Sql Server 2012..but when I try do add them in InstallShield via Redistributables, but it keeps saying that Needs to be downloaded . 另外,我已经在计算机.NET Framework 4.5上安装了Sql Server 2012 ..,但是当我尝试通过Redistributables将它们添加到InstallShield中时,却一直说Needs to be downloaded Why? 为什么?

UPDATE 更新

I have this Class where I make the conenction. 我在这堂课上做文章。 But I receive error: Additional information: Illegal characters in path. 但是我收到错误消息: Additional information: Illegal characters in path. at that line: 在那一行:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;

namespace simulator
{
    class ConnConfig
    {
        private static string conn = "Data Source=c:\aplicatie.db;Version=3;Password=myPassword;";
        public static SQLiteConnection connect = null;

        private ConnConfig()
        {

        }
        public static SQLiteConnection getConnection()
        {
            SQLiteConnection connect = null;
            try
            {
                connect = new SQLiteConnection(conn);
                connect.Open();// here I receive the error
                return connect;
            }
            catch (SQLiteException e)
            {
                throw new Exception("Cannot connect", e);
            }
        }
    }
}

UPDATE 3 更新3

In that class I make the connection to database. 在该课程中,我建立了与数据库的连接。 In the other forms I just use tables and their data. 在其他形式中,我只使用表及其数据。 For connection to program, I use a login form which uses this class to getConnection() . 为了连接程序,我使用了一个登录表单,该表单使用该类的getConnection() I created that database by adding an ADO.NET in simulator project. 我通过在模拟器项目中添加ADO.NET创建了该数据库。 And with that, it comes those 2 tables that I already have in localhost server. 随之而来的是,我已经在本地主机服务器中拥有的那两个表。 So, Is ok if I have to create another empty database with new tables, but where to include that code or how to use it, because I don't get how that script works..where should I put it? 所以,如果我必须用新表创建另一个空数据库,但是在哪里包括该代码或如何使用它,是可以的,因为我不知道该脚本的工作原理。

If your database is going to be installed on each client and your tables are not massive you might want to look at something lighter like SQLite which doesn't need any installation just the dlls and is very fast and efficient and only runs when your program does. 如果您的数据库要安装在每个客户端上,并且您的表不是很大,那么您可能希望查看类似SQLite的工具,该工具不需要dll的任何安装,并且非常快速高效,并且仅在程序执行时运行。

As for for the Needs to be Downloaded issue, it seems you have not setup your prerequisite correctly, you an correct this by following the steps in this article Adding InstallShield Prerequisites, Merge Modules, and Objects to Basic MSI and InstallScript MSI Projects 至于“需要下载的问题”,看来您没有正确设置先决条件,请按照本文中的步骤进行更正, 将InstallShield先决条件,合并模块和对象添加到Basic MSI和InstallScript MSI项目中

You might want to look into determining if MySQL is the right solution for you. 您可能需要研究确定MySQL是否适合您。

SQLite vs MySQL vs PostgreSQL: A Comparison Of Relational Database Management Systems SQLite vs MySQL vs PostgreSQL:关系数据库管理系统的比较

And to see the limitations of SQLite SQLite 并查看SQLite的局限性SQLite

Because honestly seems like overkill to install MySQL on every system. 老实说,在每个系统上安装MySQL似乎是过大的。 If you had one server with MySQL on the network, okay. 如果您在网络上有一台装有MySQL的服务器,那么可以。 But on every system seems like a bad idea. 但是在每个系统上似乎都不是一个好主意。

As far as connecting to an SQLite database here is a List of Connection Strings for SQLite 至于连接到SQLite数据库,这里是SQLite 的连接字符串列表

See this topic on how to create Databases and tables Create SQLite Database and table 请参阅有关如何创建数据库和表的主题。 创建SQLite数据库和表

My guess is your program doesn't bundle up the database alongside the setup upon deployment. 我的猜测是您的程序在部署时不会将数据库与设置捆绑在一起。 This may be due to the fact that you didn't mark your database as a Data File in the Project Files . 这可能是由于您没有在项目文件中将数据库标记为数据 文件 Try this, right click on your project name in Solution Explorer and select Properties from Menu. 尝试此操作,在解决方案资源管理器中右键单击您的项目名称,然后从菜单中选择属性 From the horizontal tabs click on the Publish Tab. 在水平选项卡中,单击发布选项卡。 Under Install Mode and Settings click the Application Files button. 在“ 安装模式和设置”下,单击“ 应用程序文件”按钮。 A dialog box appears with all Application files. 将出现一个对话框,其中包含所有应用程序文件。 Set your database Publish Status to Data File from the drop down on the corresponding cell. 从相应单元格的下拉列表中将数据库的“ 发布状态”设置为“ 数据文件 ”。 This way your database will be bundled together with the setup upon publishing. 这样,您的数据库将在发布时与设置捆绑在一起。 Hope this helps. 希望这可以帮助。

您可以通过ODBC访问SQLite。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM