-
Jul 9th, 2013, 12:20 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] ODBC Connection to local MySQL DB throws "Datasource Name not Found"
Hi Everyone
I'm busy working on an ASP.NET Web Application (3.5) and can't seem to connect to a MySQL DB. I first created the entire application using a WinForms template and everything works 100%, but as soon as I move the exact same code to the Web Application, I can't connect anymore. Here's the code:
Code:
public class DBC
{
OdbcConnection connection;
public bool CreateConnection()
{
try
{
string connFormat = "Driver={MySQL ODBC 5.1 Driver};Server=[SERVER];Database=[DBNAME];User=[UID];Password=[PWD];";
connFormat = connFormat.Replace("[SERVER]", Properties.Settings.Default.DBServer);
connFormat = connFormat.Replace("[DBNAME]", Properties.Settings.Default.DBName);
connFormat = connFormat.Replace("[UID]", Properties.Settings.Default.DBUser);
connFormat = connFormat.Replace("[PWD]", Properties.Settings.Default.DBPassword);
connection = new OdbcConnection(connFormat);
connection.Open();
return true;
}
catch (Exception ex)
{
return false;
}
}
As soon as I try to create the new OdbcConnection instance, I get the error:
Code:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
As noted this works in a WinForms app, and even more strange is that I don't even specify a DSN name...
All I could find from reading through forums all over the internet is suggestions of downgrading the MySQL ODBC driver version, which I'd really rather not...
Any ideas?
-
Jul 9th, 2013, 12:49 AM
#2
Re: ODBC Connection to local MySQL DB throws "Datasource Name not Found"
Please mark you thread resolved using the Thread Tools as shown
-
Jul 9th, 2013, 12:56 AM
#3
Re: ODBC Connection to local MySQL DB throws "Datasource Name not Found"
Firstly I would suggest that you use Connector/Net rather than ODBC. If you do that then issue may well go away because you're not using ODBC. Secondly, I would suggest using the appropriate connection string builder for your provider, e.g. OdbcConnectionStringBuilder, to set connection string fields.
-
Jul 9th, 2013, 08:24 AM
#4
Thread Starter
Hyperactive Member
-
Jul 9th, 2013, 08:24 PM
#5
Re: [RESOLVED] ODBC Connection to local MySQL DB throws "Datasource Name not Found"
That sounds like a perfectly good reason to use ODBC to me. I think that you should be able to deploy the Connector/Net DLL with your app, so it would work even if the host hasn't installed it. Never tried myself though.
If you can upgrade to VS 2010 or later then you can also use IIS Express, which runs as a 64-bit process on 64-bit systems. The Cassini web server built into VS is fairly basic and, as VS is a 32-bit app, runs as a 32-bit process.
-
Jul 10th, 2013, 04:32 PM
#6
Re: [RESOLVED] ODBC Connection to local MySQL DB throws "Datasource Name not Found"
Early web server build on VS could be basic but the damn IIS Express with VS2012 is hanging on me right now for about 3 minutes....Ahh after 4 minutes i got the page to open. Suupeeer!!
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|