A
Alan T
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?
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?