From: Alan T on
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?


From: Brian Cryer on
"Alan T" <alan_NO_SPAM_pltse(a)yahoo.com.au> wrote in message
news:e$UtxLxJLHA.680(a)TK2MSFTNGP04.phx.gbl...
>I have installed ODBC driver for MySQL.
<snip>
> So I think I cannot us SqlConnection for MySQL?

Yes. SqlConnection is specific for Microsoft SQL Server, so you can't use it
with MySQL.

> What object should I use instead of SqlConnection?

Use either MySqlConnection or OdbcConnection.

I think the MySqlConnection is a download from the mysql site, but I'm not
sure as I don't use it myself.

Personally I'd advocate using OdbcConnection (and OdbcDataReader etc) as you
can then later change the type of database you are connected to without any
change other than the connection string. I use OdbcConnection to connect to
both MySQL and SQL Server (plus a few others).

Hope this helps.
--
Brian Cryer
http://www.cryer.co.uk/brian

From: Man T on

>> What object should I use instead of SqlConnection?
>
> Use either MySqlConnection or OdbcConnection.
>
> I think the MySqlConnection is a download from the mysql site, but I'm not
> sure as I don't use it myself.
>
> Personally I'd advocate using OdbcConnection (and OdbcDataReader etc) as
> you can then later change the type of database you are connected to
> without any change other than the connection string. I use OdbcConnection
> to connect to both MySQL and SQL Server (plus a few others).

Hi,

Could you give me some code that I can use to replace in my original coding?


From: Simon Whale on
http://dev.mysql.com/downloads/connector/net/ - that is the download site

there is not much to change with this connector, but mainly sqlconnection to
mysqlconnection etc

"Man T" <alanpltse_NOSPAM(a)yahoo.com.au> wrote in message
news:uY2e$GzJLHA.680(a)TK2MSFTNGP04.phx.gbl...
>
>>> What object should I use instead of SqlConnection?
>>
>> Use either MySqlConnection or OdbcConnection.
>>
>> I think the MySqlConnection is a download from the mysql site, but I'm
>> not sure as I don't use it myself.
>>
>> Personally I'd advocate using OdbcConnection (and OdbcDataReader etc) as
>> you can then later change the type of database you are connected to
>> without any change other than the connection string. I use OdbcConnection
>> to connect to both MySQL and SQL Server (plus a few others).
>
> Hi,
>
> Could you give me some code that I can use to replace in my original
> coding?
>


From: Alan T on
Hi,

I have installed both .NET connector and ODBC driver.
Since the connecting string format for MySQL is the same, how does ASP.NET
knows which one to use to connect?

> http://dev.mysql.com/downloads/connector/net/ - that is the download site
>
> there is not much to change with this connector, but mainly sqlconnection
> to mysqlconnection etc
>
>>>> What object should I use instead of SqlConnection?
>>>
>>> Use either MySqlConnection or OdbcConnection.
>>>
>>> I think the MySqlConnection is a download from the mysql site, but I'm
>>> not sure as I don't use it myself.
>>>
>>> Personally I'd advocate using OdbcConnection (and OdbcDataReader etc) as
>>> you can then later change the type of database you are connected to
>>> without any change other than the connection string. I use
>>> OdbcConnection to connect to both MySQL and SQL Server (plus a few
>>> others).
>>
>> Hi,
>>
>> Could you give me some code that I can use to replace in my original
>> coding?


 |  Next  |  Last
Pages: 1 2
Prev: MVC
Next: Auto redirect http to https