newbie: db connection works in console app but not asp.net page

E

Engwar

I'm just getting started with asp.net using C# and I'm attempting to
connect to a mySQL database.

I can do so using some C# code I've found on the web for a console
application. It works successfully and returns my data. However, when
I attempt to adapt that code for use in an asp.net page I get a
compilation error when trying to import the following.

Import Namespace="Microsoft.Data.Odbc"

Since it works as a console app as "using Microsoft.Data.Odbc;" but
not as an asp.net page with "Import" I would think I don't have IIS
configured properly? Am I correct? What do I do to fix this?

I can post more code if need be but it's choking on that Import
statement.

Thanks.
 
A

Andrew Gnenny

Hi,

If you use the ".NET Framework Data Provider for ODBC" then the code will
looks like this:
<%@ Import Namespace="System.Data.Odbc"%>

Also, the System.Data assembly should be referenced in the project.
 
N

Nicholas Paldino [.NET/C# MVP]

Engwar,

What exactly is the error? Usually when accessing data in ASP, it is a
matter of authorization and authentication.
 
E

Engwar

The error I was getting was...

CS0234: The type or namespace name 'Data' does not exist in the class
or namespace 'Microsoft' (are you missing an assembly reference?)

with the line being highlighted as

<%@ Import Namespace="Microsoft.Data.Odbc" %>

I found another example on-line that had the following line after the
one above...

<%@ Assembly Name = "Microsoft.Data.Odbc" %>

I added that and recieved a different error

File or assembly name Microsoft.Data.Odbc, or one of its dependencies,
was not found.

The error message gave a list of directories it was searching through.
I found the file Microsoft.Data.Odbc.dll elsewhere on my machine and
copied it into one of these directories. That did the trick!

Here's my new question. Instead of manually moving this file is there
a correct way to tell the application where that .dll was? Through
..Net Framework Configuration-->Configure an assembly or through
editing a web.config file? I tried the former and had no luck.

PS, I'm not using Visual Studio right now. Just doing this all with a
text editor. So anything VS does automatically for you I'll be doing
manually.

Thanks for the responses!


Nicholas Paldino said:
Engwar,

What exactly is the error? Usually when accessing data in ASP, it is a
matter of authorization and authentication.


--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

Engwar said:
I'm just getting started with asp.net using C# and I'm attempting to
connect to a mySQL database.

I can do so using some C# code I've found on the web for a console
application. It works successfully and returns my data. However, when
I attempt to adapt that code for use in an asp.net page I get a
compilation error when trying to import the following.

Import Namespace="Microsoft.Data.Odbc"

Since it works as a console app as "using Microsoft.Data.Odbc;" but
not as an asp.net page with "Import" I would think I don't have IIS
configured properly? Am I correct? What do I do to fix this?

I can post more code if need be but it's choking on that Import
statement.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top