Please help me!

This example of Web Service run with success on Windows with VisualStudio and
IIS, but when I try to run on Linux (FC2) with Mono (Beta1),I get this error :
"The remote server returned an error: (500) Internal Server Error.
Object reference not set to an instance of an object"


The method that gives problem is TestLogin......Why? Which is the correct
solution?

WebService code is :LoginService.asmx.cs


Thanks,

Valentina.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.Odbc;

namespace LoginService
{
	/// <summary>
	/// Summary description for Service1.
	/// </summary>
	public class LoginService : System.Web.Services.WebService
	{
		public LoginService()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
		}

		#region Component Designer generated code
		
		//Required by the Web Services Designer 
		private IContainer components = null;
				
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion
		//##############################################################################
		//LOGIN
		[WebMethod (EnableSession=true)]		
		public bool Login( string LoginInserita, string PasswordInserita)
		{				
			OdbcConnection conn = new OdbcConnection("DRIVER=MySQL;SERVER=localhost;DATABASE=login;UID=root;PASSWORD=rootpwd;");
			OdbcDataReader dbReader = null;
			conn.Open();
			OdbcCommand cmd = conn.CreateCommand();
			cmd.CommandText = "Select * from login where Login='"+ LoginInserita+"' and Password='"+PasswordInserita+"'"; 
			dbReader = cmd.ExecuteReader();
			if(dbReader.Read())
			{	
				Session.Add("Login", LoginInserita);
				dbReader.Close();
				conn.Close();
				return	true;
			}
			else
			{	
				dbReader.Close();
				conn.Close();
				return false;				
			}						
		}
		//##############################################################################
		//TEST LOGIN
		[WebMethod (EnableSession=true)]
		public string TestLogin ()
		{
			if ((string)Session["Login"]!= null)
			{
				//return (string)Session["Login"];
				OdbcConnection conn = new OdbcConnection("DRIVER=MySQL;SERVER=localhost;DATABASE=login;UID=root;PASSWORD=rootpwd;");
				OdbcDataReader dbReader = null;
				conn.Open();
				OdbcCommand cmd = conn.CreateCommand();
				cmd.CommandText = "Select RuoloAziendale from login where Login ='"+(string)Session["Login"]+"'";
				dbReader = cmd.ExecuteReader();
				if(dbReader.Read())
				{
					Session.Add("Ruolo",(string)dbReader["RuoloAziendale"] );			
					dbReader.Close();
					conn.Close();
				}
				return (string)Session["Ruolo"];
			}
			else
			{
				return "need to login";
			}
		}		
		//##############################################################################
		//LOGOUT
		[WebMethod (EnableSession=true)]
		public bool Logout()
		{
			Session.RemoveAll();
			return false;
		}
	}
}

Reply via email to