Domanda

I have the annoying task of hooking a c# aspx page up to postgresql with Npgsql.

The problem that i have is that when i try to import Npgsql, i get the following aspx error message returned:

CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?)

I have a javascript function that calls the aspx page below to get data from the db:

<%@ language="C#"%>
<%@ Import Namespace="Npgsql" %>
<%

  // PostgeSQL-style connection string
  string connstring = String.Format("Server=localhost;Port=5432;UID=posgres;Password=pass;Database=postgres_db;";
  NpgsqlConnection conn = new NpgsqlConnection(connstring);      
  conn.Open();
%>

Im assuming i need to set it up in my web.config, but i cannot for the life of me it out.

Any help would be greatly appreciated! Thanks.

È stato utile?

Soluzione

Your problem is the Npgsql.dll that is not being references. You only import the Namespace.

It's not best practice to hack SQL into a ASP.NET document... The solution would be adding the DLL to the web.config file:

 ...
  <system.web>         
    <compilation debug="true" targetFramework="4.5">                              
      <assemblies> 
        <add assembly="Npgsql, Version=2.0.11.93, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />  
  ...

But I recommend to create a class library project or at least a Web Application project using Visual Studio (Express version is FREE). Then right click on the directory named references and add the DLL there. Why? N-Tier (http://en.wikipedia.org/wiki/Multitier_architecture): better organization of code by it's intent. Easier to find errors and change/maintain code...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top