[Mono-list] Databind to SQLServer

Jones, Larry LJones@Lithonia.com
Thu, 15 May 2003 23:38:30 -0700


I have done so many different versions of this I get confused.  I had:
<%@ Import Namespace="System.Data.SqlClient" %>

and I had 

<%@ Import Namespace="System.Data" %>

at one point.  (Seems like in the previous release this worked,...)  So, I
added it back in, and now I don't get any data back.  Its essentially the
same exact code as in my C# program, which does pull the data.  Heres the
complete aspx page:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="C#" %>


<script runat="server">
public void Page_Load()
{
	 SqlDataReader reader;
       string connectionString = "Server=SERVER;Database=pubs;User
ID=sa;Password=password";
       SqlConnection dbcon;
       dbcon = new SqlConnection(connectionString);
       dbcon.Open();
       SqlCommand dbcmd = dbcon.CreateCommand();
       string sql = 
           "SELECT au_fname, au_lname " +
           "FROM Authors";
       dbcmd.CommandText = sql;
       reader = dbcmd.ExecuteReader();
	while(reader.Read()) {
		string FirstName = reader["au_fname"].ToString();
		string LastName = reader["au_lname"].ToString();
		Console.WriteLine("Name: " + FirstName + " " + LastName);
	 } 

       reader.Close();
       dbcon.Close();

 }
</script>
<Html>
	<Body>
		<H2>Testing Sql</H2>
	</Body>
</Html>

This code used to work under Mono 0.24 and mod_mono 3.6 (on RH 8.0, now on
RH 9.0)

Larry Jones
Hydrel/Lithonia Lighting


-----Original Message-----
From: Adam W Root [mailto:rootad@engr.orst.edu]
Sent: Thursday, May 15, 2003 11:33 PM
To: Jones, Larry
Cc: 'mono-list@lists.ximian.com'
Subject: RE: [Mono-list] Databind to SQLServer


You need to add an Import directive:

<%@ Import Namespace="System.Data" %>

If it says it can't find the assembly, use an Assembly directive (the
syntax here is iffy, but i think it's right):

<%@ Assembly name="System.Data.dll" %>

Good luck!



On Thu, 2003-05-15 at 23:16, Jones, Larry wrote:
> I already got it with:
> 
> mcs myclass.cs -r System.Data.dll
> 
> But haven proven that I can access MS SQL Server from a C# program, I now
> have the same problem of it not recognizing the System.Data Class from an
> ASP.NET page.
> 
> Larry Jones
> Hydrel/Lithonia Lighting
> 
> 
> -----Original Message-----
> From: Mark Gimelfarb [mailto:mgimelfarb@configtech.com]
> Sent: Thursday, May 15, 2003 9:49 PM
> To: mono-list@lists.ximian.com
> Subject: RE: [Mono-list] Databind to SQLServer
> 
> 
> 
> The syntax is 
> 
> mcs /r:System.Data myclass.cs
> 
> You might have to include the full filename for the assembly, depending
> on your mono config.
> 
> Good luck,
> 
> Mark.
> 
> 
> -----Original Message-----
> From: mono-list-admin@lists.ximian.com
> [mailto:mono-list-admin@lists.ximian.com] On Behalf Of John BouAntoun
> Sent: Thursday, May 15, 2003 11:40 PM
> To: Jones, Larry; mono-list@lists.ximian.com
> Subject: RE: [Mono-list] Databind to SQLServer
> 
> You need to reference the assemnlies that those Namespaces are in.
> 
> simply including a :
> 
> using [Namespace]
> 
> Statement at the top of a c# file is not enough. The compiler needs to
> know what binary (i.e. what Assmebly) that Namespace is in.
> 
> Both System.Data and System.Data.SqlClient are in the System.Data.Dll
> assembly.
> 
> When compiling your project you need to pass in all the assemblies you
> want the compiler to reference for your files (i.e. all the assemblies
> that your 'using' statements need.
> 
> I'm not quite sure off the top of my head the syntax for assembly
> references in mcs is, but do a mcs /? or man mcs and it will explain
> 
> JBA
> 
> -----Original Message-----
> From: Jones, Larry [mailto:LJones@Lithonia.com]
> Sent: Friday, 16 May 2003 2:27 PM
> To: John BouAntoun
> Subject: RE: [Mono-list] Databind to SQLServer
> 
> 
> I have these:
> 
>  using System;
>  using System.Data;
>  using System.Data.SqlClient;
> 
> just as in the sample.
> 
> Larry Jones
> Hydrel/Lithonia Lighting
> 
> 
> -----Original Message-----
> From: John BouAntoun [mailto:jbouantoun@rogen.com.au]
> Sent: Thursday, May 15, 2003 9:29 PM
> To: Jones, Larry
> Subject: RE: [Mono-list] Databind to SQLServer
> 
> 
> are you referencing the System.Data Assembly?
> 
> -----Original Message-----
> From: Jones, Larry [mailto:LJones@Lithonia.com]
> Sent: Friday, 16 May 2003 2:20 PM
> To: 'mono-list@lists.ximian.com'
> Subject: [Mono-list] Databind to SQLServer
> 
> 
> OK, I tried the sample program for Sql Server in the doc, which is just
> straight C#, not ASP.NET, and the compile fails on:
> 
> The namespace 'System.Data' can not be found 
> and
> The namespace 'System.Data.SqlClient' can not be found
> 
> Help guys.
> 
> Larry Jones
> Hydrel/Lithonia Lighting
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list