[Mono-bugs] [Bug 60204][Wis] New - DataSet filling with ASP.NET Application, PgSql Database

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 15 Jun 2004 08:12:27 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by yom@iaelu.net.

http://bugzilla.ximian.com/show_bug.cgi?id=60204

--- shadow/60204	2004-06-15 08:12:27.000000000 -0400
+++ shadow/60204.tmp.6148	2004-06-15 08:12:27.000000000 -0400
@@ -0,0 +1,230 @@
+Bug#: 60204
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: Crux 1.3 (http://crux.nu/), kernel 2.6.6-bk9
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: yom@iaelu.net               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: DataSet filling with ASP.NET Application, PgSql Database
+
+Description of Problem:
+I'm experiencing some problem with DataSet object and mod-mono-server.exe.
+I'm not getting the expected results in an asp.net web application, while
+I'm getting the expected ones in a simple console application, with the
+same code to access a PgSql database.
+
+I will try to explain as well as i can so that there is no misunderstanding
+I've developped a little web application wiht asp.net and a PgSql Database,
+in which I'm getting some IDs and strings in a DataSet.
+To make the application with a bit more of security, I've used some
+PL/PgSql functions, and I'm calling them with Npgsql Library via a
+NpgsqlDataAdapter so i can fill the DataSet object with
+NpgsqlDataAdapter.Fill(DataSet).
+Then i'm trying to show the DataSet with a DataGrid object.
+Here is a formated sample result :
+
+id_user: (null)
+id_app: (null)
+url_app: http://www.yyy.zzz/admin/app_login.aspx
+name_app: Admin
+
+id_user: (null)
+id_app: (null)
+url_app: http://www.yyy.zzz/download/app_login.aspx
+name_app: Download
+
+While the expected results should have been :
+id_user: 1
+id_app: 1
+url_app: http://www.yyy.zzz/admin/app_login.aspx
+name_app: Admin
+
+id_user: 1
+id_app: 4
+url_app: http://www.yyy.zzz/download/app_login.aspx
+name_app: Download
+
+
+Here is the sample code i used to get the expected results, which is the
+same source code i've used to developp my web application:
+
+### CODE Data.cs ###
+
+using System;
+using System.Data;
+using Npgsql;
+using IaeluAppsLib;
+
+public class Driver
+{
+    public static void Main(string[] args)
+    {
+        DataSet ds = new DataSet();
+        NpgsqlDataAdapter da;
+        try {
+            IaeluDbConnection.GetConnection();
+        } catch (Exception ex) {
+            Console.WriteLine("No connection !");
+            Environment.Exit(0);
+        }
+       
+        try {
+            string SQL = "select * from
+get_applications_by_user_login('yom')" +
+                " AS (id_user int, id_app int, url_app varchar, name_app
+varchar, desc_app text)";
+            da = new NpgsqlDataAdapter(SQL,
+(NpgsqlConnection)IaeluDbConnection.cnc);
+            da.Fill(ds);
+            for (int i=0; i < ds.Tables[0].Rows.Count; i++) {
+                Console.WriteLine("id: " + ds.Tables[0].Rows[i][0] +
+                    " id: " + ds.Tables[0].Rows[i][1]);
+            }
+        } catch (Exception ex) {
+            Console.WriteLine(ex.Message);
+        }
+    }
+}
+
+### CODE ###
+
+### CODE IaeluDbConnection.cs ###
+
+using System;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Configuration;
+using System.Data;
+using Npgsql;
+
+namespace IaeluAppsLib
+{
+	public class IaeluDbConnection
+	{
+		public static IDbConnection cnc;
+		protected static Type cncType = null;
+		
+		static IaeluDbConnection() { }
+		
+		private static void GetConnectionData (out string providerAssembly, out
+string cncTypeName, out string cncString)
+		{
+			providerAssembly = null;
+			cncTypeName = null;
+			cncString = null;
+
+			if (providerAssembly == null || providerAssembly == "")
+				providerAssembly = "Npgsql";
+	
+			if (cncTypeName == null || cncTypeName == "")
+				cncTypeName = "Npgsql.NpgsqlConnection";
+	
+			if (cncString == null || cncString == "")
+				cncString = "Server=127.0.0.1;Port=5432;User
+Id=user;Password=password;Database=database";
+
+		}
+
+		public static void GetConnection()
+		{
+			string connectionTypeName;
+			string providerAssemblyName;
+			string cncString;
+	
+			GetConnectionData (out providerAssemblyName, out connectionTypeName, out
+cncString);
+			if (cncType == null) {
+				Assembly dbAssembly = Assembly.Load (providerAssemblyName);
+				cncType = dbAssembly.GetType (connectionTypeName, true);
+				if (!typeof (IDbConnection).IsAssignableFrom (cncType))
+					throw new ApplicationException ("The type '" + cncType +
+									"' does not implement IDbConnection.\n" +
+									"Check 'DbConnectionType' in web.config.");
+			}
+	
+			cnc = (IDbConnection) Activator.CreateInstance (cncType);
+			cnc.ConnectionString = cncString;
+			try
+			{
+				cnc.Open ();
+			}
+			catch (Exception exc)
+			{
+				cnc = null;
+				throw(new Exception(exc.Message));
+			}
+		}
+	}
+}
+
+### CODE ###
+
+### PL/PgSQL function ###
+
+Functions 	                Arguments       	Returns 	Programming language
+get_applications_by_user_login 	character varying 	setof record 	plpgsql
+
+Definition
+
+DECLARE
+ rec RECORD;
+BEGIN
+ FOR rec IN SELECT DISTINCT iaelu_users.id_user AS id_user,
+   iaelu_apps.id_app AS id_app,
+   iaelu_apps.url_app AS url_app,
+   iaelu_apps.name_app AS name_app,
+   iaelu_apps.desc_app AS desc_app 
+  FROM iaelu_users INNER JOIN iaelu_apps_groups
+   ON iaelu_users.id_group = iaelu_apps_groups.id_group 
+  INNER JOIN iaelu_apps 
+   ON iaelu_apps_groups.id_app = iaelu_apps.id_app 
+  WHERE iaelu_users.login_user = $1
+ LOOP
+  RETURN NEXT rec ;
+ END LOOP ;
+
+ RETURN ;
+END
+
+
+Properties
+VOLATILE
+RETURNS NULL ON NULL INPUT
+SECURITY INVOKER
+
+### PL/PgSQL function ###
+
+Some data :
+
+iaelu_apps
+id_app 	name_app
+1	Iaelu Admin
+4	Private Download
+
+iaelu_users
+id_user         id_group        login_user
+1               1               yom
+
+iaelu_apps_groups
+id_apps_groups  id_app  id_group
+19              1       1
+24              4       1
+
+
+Wrong results happen in the Web Application (so, using mod-mono-server.exe)
+Good results happen in the Console Application.
+Both are using Npgsql the same way
+For what I've seen while testing my web application, it is the dataset that
+isn't filled correctly.
+
+I hope these sources samples can help you.