I have a windows application that I am making for a friend, but for some reason, when I try to connect, the app crashes. a message box pops up and says "DBTest hastopped working, windows is checking for a solution to the problem..." after 5 seconds, it closes and the app doesn't launch.
However, when I comment out the info from the app, it works again, but only the app launches, and I can't connect anymore??
I checked the connection on MySQL workbench, and it lets me connect to the website's database, and I can connect to the sites DB remotely, but it will not allow me to do so in the application.
Heres the code that im testing, and the app keeps crashing.
I'm at a loss.
public partial class Form1 : Form
{
public MySqlConnection connection;
public Form1()
{
InitializeComponent();
DBInfo db = new DBInfo();
string server;
string database;
string uid;
string password;
server = "XXX";
database = "XXX";
uid = "XXX";
password = "XXX";
string connectionString;
connectionString = "Server=" + server + ";" + "Database=" + database + ";"
+ "Uid=" + uid + ";" + "Password" + password + ";";
connection = new MySqlConnection(connectionString);
try
{
connection.Open();
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
MessageBox.Show("Cannot connect to Server. Contact Admin.");
break;
case 1045:
MessageBox.Show("Invalid Username/Password, please try again.");
break;
}
}
}
UPDATE:
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 54. at System.Data.Common.DBConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstkey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean use OdbcRules) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnectionStringBuilder..ctor(string connStr) at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString) at DBtest.Form1..ctor() in C:\Users\AlexMoreno\Dcouments\Visual Studio\2008\Projects\DBtest\Form1.cs:line 38
connection.Open();
and add try/catch logic that was not there originally...changes the question quite a bit. ;) – J0e3ganconnection.Open();
statement that you originally had commented out in your code, or does it mean other code that you have not shown commented out? It is tough to hit a target that is shifting and unclear. – J0e3gan