From: Leon on
Hi,

use the MySQL - Connector/Net

http://dev.mysql.com/downloads/connector/


With something like that you can access the DB.
----------------------------------------------------------------

public void check_DB_Daten(string dbserver, string dbuser, string dbpass, string dbport, string dbname, string dbtabelle)
{
List<string> ausgabe_dbcheck = new List<string>();
string MyConString = "server=" + dbserver + ";" +
"uid=" + dbuser + ";" +
"database=" + dbname + ";" +//"database=devsql;" +
"port=" + dbport + ";" +
"pwd=" + dbpass + ";";
MySqlConnection connection = new MySqlConnection(MyConString);
try
{
MySqlDataReader Reader;
MySqlCommand mycommand = new MySqlCommand("SHOW DATABASES", connection);
connection.Open();
Reader = mycommand.ExecuteReader();
while (Reader.Read())
{
for (int i = 0; i < Reader.FieldCount; i++)
{
ausgabe_dbcheck.Add(Reader.GetValue(i).ToString());
}
}
Reader.Close();
connection.Close();
//---------------------------------------------------------------------
//List<string> myList f?ttert hier einen string per ForEach Funktion
string dbausgabe = "Die Verbindung ist OK!\n\nSHOW DATABASES:\n\n";
ausgabe_dbcheck.ForEach(delegate(String name)
{
dbausgabe += name + "\n";
});
//MessageBox.Show(dbausgabe, "Verbindung OK");
//---------------------------------------------------------------------
dbverbindung_ok = true;
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message, "DB Fehler aufgetreten!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
dbverbindung_ok = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "DB Fehler aufgetreten!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
dbverbindung_ok = false;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}

----------------------------------------------------------

Leon-Peon



Alan T wrote:

SqlConnection problem - MySQL
19-Jul-10

I have installed ODBC driver for MySQL.
This is my Web.Config:

<add name="spotitConnectionString"
connectionString="DSN=MySQL_server;UID=spotit;description=Connection to
remote MySQL;server=access;database=spotit;port=3306;pwd=traffic54"
providerName="System.Data.Odbc"/>


I had an exception of the connection string of the DSN unrecognized.



This is my method:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Web.UI.WebControls;
using System.Data.Odbc;
using System.Data;
using System.Data.SqlClient;

protected DataSet ExecuteDataSet(string query)
{
SqlConnection connection;
SqlCommand cmd;
SqlDataAdapter da;

connection = null;
cmd = null;
DataSet ds = new DataSet();
da = new SqlDataAdapter();

try
{
cmd = new SqlCommand(query);
cmd.CommandType = CommandType.Text;

da.SelectCommand = (SqlCommand)cmd;

connection = new SqlConnection(GetConnectionString());
cmd.Connection = connection;
connection.Open();

// fill the dataset
da.Fill(ds);
}
catch
{
throw;
}
finally
{
if (da != null)
da.Dispose();
if (cmd != null)
cmd.Dispose();
// implicitly calls close()
connection.Dispose();
}
return ds;
}


So I think I cannot us SqlConnection for MySQL?
What object should I use instead of SqlConnection?

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Six Free Visual Studio 2010 MSDN Memberships Giveaway
http://www.eggheadcafe.com/tutorials/aspnet/f7338bb9-7fa4-4fa8-9e5a-244857b0d9d4/six-free-visual-studio-2010-msdn-memberships-giveaway.aspx