Data source name not found and no default driver s

2019-09-05 08:40发布

问题:

The Error

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The Story

I've written a page outside of Visual Web Developer 2010 that uses a SqlDataSource object along with a FormView object that works perfect. Building upon those awesome skills I obtained I started to build a project within Visual Web Developer, this time creating an Empty Web Application and went along my happy way building my new site. I used the same techniques and almost the same code as before - just pointing to a different table but I was met with the aforementioned error message.

The Confusing part

Here's the puzzling part - if I take my page I wrote outside of Visual Web Developer, again - it works perfect - no complaints, and add it as a page to the project I've built it now presents the same error message and I have no idea why.

The Tests Completed

I've backed off of targeting .NET 4.0 framework and went to 2.0 as I am not using any specific 4.0 controls or methods at this time. I've taken my page that originally gave me issue and recreated it outside of a Visual Web Developer project and instead as a stand alone page and the exact same code - copy, cut, paste - works perfect!

The Solution...

At this point I'm left puzzled and mouth agape. Any help is appreciated why building a project in Visual Web Developer would cause anything different.

回答1:

If you're running (e.g. debugging) your project within Visual Web Developer / Visual Studio / etc, it's likely running using the embedded web server. The embedded web server puts itself in a "sandbox" so it won't inherit any of the attributes set in the toplevel application / web site.

Where do you configure the data source name for your SQL connection? In the top level web site? In a parent application?

Does it work if you change the project properties to target local IIS instead of running on the embedded web server?

If so, you'll just have to move the connection string to the local web.config file, so that your new application can find it.



回答2:

I should learn to read the answers to my own questions I posted no more than 2 weeks ago.

MySQL ODBC fails in C# .NET project but not runtime compiled code

Updating the connectionString to

DRIVER={MySQL ODBC 5.1 Driver};

instead of

DRIVER={MySQL ODBC 3. Driver};

seems to have corrected the issue once I fixed a stupid SQL Insert Statement issue.

Thanks for the help mwalker.