-1

I have a project in C# which is created in Visual Studio 2013. I want to create an installer using Install Shield free version. 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. 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. 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. ConnConfig is a class where is the connection and getConnection() is a function from ConnConfig which return connection. II tried to install on another computer .NET Framework 4.5.2, SQL Server, but also didn't worked. In my project, I use localhost server where I have a database with 2 tables. 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. Why?

UPDATE

I have this Class where I make the conenction. But I receive error: 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

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(). I created that database by adding an ADO.NET in simulator project. 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?

dpaul1994
  • 332
  • 3
  • 16
  • Your application is lacking basic error handling. `Unable to connect to any of the specified MySQL hosts.` means your application cannot reach the database. Make sure it's reachable by the other computer. – nvoigt Mar 21 '15 at 15:54
  • And how can I do that? That's my problem – dpaul1994 Mar 21 '15 at 15:55
  • Is your database going to be installed on each client or are you going to have a server? Also you mention MySQL and SQL Server which one is it? These two tables are large or small? – carbo18 Mar 21 '15 at 15:59
  • Aaa my mistake, I did not know exactly, I said to them say. Is MySql. Well, I want to be installed on each client. I create it and they just have to use it without internet connection. They are pretty large, yes, at least will be at the final of the project and is possible to create more tables but only one database will be. – dpaul1994 Mar 21 '15 at 16:07
  • How many columns or rows? Two tables doesn't seem that big. Is this DB IO intensive? Write or Read? – carbo18 Mar 21 '15 at 16:17
  • Well, I can't say that because project is not already finished, but tables have like 10-15 columns and one of tables will have more than 1k rows. – dpaul1994 Mar 21 '15 at 16:20
  • Put an @ sign in front of your connection string or add a \ to escape the characters in your string so either @"Data Source=c:\aplicatie.db;Version=3;Password=myPassword;" or "Data Source=c:\\aplicatie.db;Version=3;Password=myPassword;" – carbo18 Mar 21 '15 at 17:56
  • Hmm here? `private static string @conn = "Data Source=c:\aplicatie.db;Version=3;Password=PassRoot!@#1994;";` – dpaul1994 Mar 21 '15 at 17:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73492/discussion-between-diacu-paul-and-carbo18). – dpaul1994 Mar 21 '15 at 18:04
  • I see :) It worked, but the string is incorrect :)) I don't know how to link database in that string..when I created ADO.NET database, I added database from localhost because he find it.. – dpaul1994 Mar 21 '15 at 18:08
  • Is not connecting to database.. – dpaul1994 Mar 21 '15 at 18:17
  • Anywhere I would modify string, I keep receive errors like: `Cannot connect` or `no such table: tabel1` – dpaul1994 Mar 21 '15 at 18:36
  • Check my last edit it should help – carbo18 Mar 21 '15 at 19:05
  • I was exactly on this page before posting last message. Is just, is different in my case. I already have a database and an ADO.NET in project... Check UPDATE 3 – dpaul1994 Mar 21 '15 at 19:14
  • My friend, don't get me wrong, but if you want to help me..you see that I'm new with this concept, explain me..how it works, how to create a right database in my case and use it as I want, because I know how to google.. – dpaul1994 Mar 21 '15 at 19:23

3 Answers3

2

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.

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

You might want to look into determining if MySQL is the right solution for you.

SQLite vs MySQL vs PostgreSQL: A Comparison Of Relational Database Management Systems

And to see the limitations of SQLite SQLite

Because honestly seems like overkill to install MySQL on every system. If you had one server with MySQL on the network, okay. 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

See this topic on how to create Databases and tables Create SQLite Database and table

Community
  • 1
  • 1
carbo18
  • 468
  • 3
  • 8
  • Interesting, I know about SQLite but I don't really know how to use it. I gone to their website, but I don't know what to download and how to include it in my project..can you help me with that or is too much? – dpaul1994 Mar 21 '15 at 16:19
  • 1
    Actually very easy. You can get the NuGet package and use it with ADO.NET, Entity Framework and LINQ. Just get the official NuGet package – carbo18 Mar 21 '15 at 16:25
  • I see. Well, I will try it right now. Thank you very much. If something goes wrong or I'm lost, you have time to help me later? – dpaul1994 Mar 21 '15 at 16:32
  • Yeah no problem or you can ask another question – carbo18 Mar 21 '15 at 16:35
  • Ok, so I added a ADO.NET database and it found my database with those 2 tables. To use this database which now, I guess, is included in project, how do I have to modify string connection? I have to mention that I have a separate class where I do the connection. – dpaul1994 Mar 21 '15 at 16:46
  • You should only need to change your code and change MySql prefixes to SQLite prefixes. Like MySqlConnection to SQLiteConnection... etc and also the connection string. See edit. – carbo18 Mar 21 '15 at 16:54
  • I see. And what about reference? I should have include System.Data.SQLite ? – dpaul1994 Mar 21 '15 at 16:56
  • Yes, you do. Add the using statement for System.Data.SQLite at the top of your class. If you used NuGet to install SQLite you should already have the reference. – carbo18 Mar 21 '15 at 17:02
  • I don't have anything like SQLite, only something named `EntityFramework`. And cannot include in `Form1.cs` `using System.Data.SQLite`. I installed it with NuGet but said it is already installed. – dpaul1994 Mar 21 '15 at 17:08
  • I can't figure it out how to do string..my current string is: `"Server=localhost;Database=aplicatie;Uid=root;Pwd=password";` I shoud do like this: `Data Source=What here?;Version=3;Password=myPassword;` – dpaul1994 Mar 21 '15 at 17:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73488/discussion-between-diacu-paul-and-carbo18). – dpaul1994 Mar 21 '15 at 17:34
  • Your connection string should look something like this. "Data Source=c:\mydb.db;Version=3;Password=myPassword;" – carbo18 Mar 21 '15 at 17:47
  • But why? My database is named `aplicatie` and I don't have nothing in c as `.db` file.. – dpaul1994 Mar 21 '15 at 17:48
1

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.

Dev
  • 1,146
  • 2
  • 19
  • 30
  • Sure, I see. But I have a big big question :)) I deploy mysql database with installer. But, I can run the software on another pc where mysql server is not installed? – dpaul1994 Mar 25 '15 at 14:26
  • 1
    Kindly rephrase your quesion, what do you mean in another pc where mysql is not installed. But if you mean installing the setup on another pc that has no MySql then you will have to set the Copy Local of MySql.Data reference to true(you do this by opening references on Solution Explorer then right clicking MySql.Data and setting Copy Local property to true.). This way the MySql.Data.dll is bundled with your setup upon publishing. I also think you will need to install the MySql connector too as its the driver your database uses to interact with your database – Dev Mar 25 '15 at 15:04
  • Thank you very much. I know that my english isn't so well, but you succeed to understand me :))) I will try this solution, is something that I haven't tried yet. – dpaul1994 Mar 26 '15 at 13:52
  • :) Ok hope bundling the database with your setup upon publishing does solve your problem. If any of the given answers solves your problem mark that entry as an answer to help those who'll ever need to know the solution to you problem. – Dev Mar 26 '15 at 14:19
  • Unfortunately, when I run it on another pc and try to connect to database, I receive: `Could not load file or assembly 'MySql.Data, Version=6.9.5.0,Culture=neutral'..This assembly is built by a tuntime newer than the currently loaded runtime and cannot be loaded.` I tried to run it on win xp and the project is builded with .net framework 3.5 sp1, which exists on pc. What do you think is the problem? – dpaul1994 Mar 26 '15 at 14:43
  • From what I have researched on, I think this is caused by difference in .Net Frameworks. So kindly check if the .Net Framework your targeting with your project is greater than the one the pc where you are installing it. If your app targeted .Net 3.5 SP1 what is the .Net Framework version in the XP machine? And is it greater or less than 3.5 SP1? – Dev Mar 26 '15 at 14:56
-1

You can access SQLite via ODBC.

i486
  • 6,491
  • 4
  • 24
  • 41
  • I was planned to add comment to carbo18's answer but sent new answer by mistake... ODBC access is programming connection from your software to SQLite. If you need DB manager for SQLite there is SQLite Expert. – i486 Mar 21 '15 at 19:41
  • Well thanks, but the biggest problem now is that when I try to add new ADO.NET database, I receive: `Your project references the latest version of Entity Framework; however, an Entity Framework database provider compatible with this version could not be found for your data connection.` – dpaul1994 Mar 21 '15 at 19:44
  • Do you know that you can delete this answer and add a comment where this belongs? – msrd0 Mar 22 '15 at 14:06