我在Visual Studio 2013中创建了一个C#项目。我想使用Install Shield免费版创建一个安装程序。我创建了一个安装程序,并试图在其他计算机上运行它,但是,当我运行它并尝试登录程序时,我遇到了关于mysql数据库的问题。错误信息是:
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.
如果我点击详细信息按钮,我会在Mysql上引用一系列错误。例如:
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
是项目的名称。 ConnConfig
是一个连接类,getConnection()
是来自ConnConfig
的函数,它返回连接。我试图在另一台计算机上安装.NET Framework 4.5.2,SQL Server,但也没有工作。
在我的项目中,我使用localhost
服务器,其中我有一个包含2个表的数据库。我的问题是,是否有可能将localhost数据库添加到安装程序并在另一台计算机上使用它?什么可再发行组件需要此操作?此外,我已经在计算机上安装了.NET Framework 4.5,Sql Server 2012 ..但是当我尝试通过Redistributables在InstallShield中添加它们时,它仍然说Needs to be downloaded
。为什么?
更新
我有这个班级,我在那里进行了联系。但我收到错误:Additional information: Illegal characters in path.
在该行:
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);
}
}
}
}
更新3
在该类中,我建立了与数据库的连接。在其他形式中,我只使用表格及其数据。对于程序的连接,我使用登录表单将此类用于getConnection()
。我通过在模拟器项目中添加ADO.NET来创建该数据库。有了它,它来自我已经在localhost服务器中的那两个表。所以,如果我必须使用新表创建另一个空数据库,但是在哪里包含该代码或如何使用它,那是好的,因为我不知道该脚本是如何工作的......我应该把它放在哪里?
答案 0 :(得分:2)
如果您的数据库将安装在每个客户端上并且您的表格不是很大,那么您可能希望看一些像SQLite一样轻松的东西,它不需要任何安装,只需要dll,而且非常快速有效且只有当你的程序运行时运行。
至于需要下载的问题,似乎您没有正确设置先决条件,请按照本文中的步骤更正 Adding InstallShield Prerequisites, Merge Modules, and Objects to Basic MSI and InstallScript MSI Projects
您可能希望了解确定MySQL是否适合您。
SQLite vs MySQL vs PostgreSQL: A Comparison Of Relational Database Management Systems
并了解SQLite SQLite
的局限性因为在每个系统上安装MySQL都显得过于苛刻。如果网络上有一台带MySQL的服务器,那好吧。但是在每个系统上看起来都是一个坏主意。
就连接到SQLite数据库而言,这里是List of Connection Strings for SQLite
请参阅本主题,了解如何创建数据库和表Create SQLite Database and table
答案 1 :(得分:1)
我的猜测是,您的程序在部署时不会将数据库与设置捆绑在一起。这可能是因为您没有在项目文件中将数据库标记为数据文件。试试这个,在解决方案资源管理器中右键单击您的项目名称,然后从菜单中选择属性。在水平标签页中,点击发布标签。在安装模式和设置下,点击应用程序文件按钮。出现一个包含所有应用程序文件的对话框从相应单元格的下拉列表中将数据库发布状态设置为数据文件。这样,您的数据库将在发布时与设置捆绑在一起。希望这会有所帮助。
答案 2 :(得分:-1)
您可以通过ODBC访问SQLite。