Please Help -- Problem with either Webservices or my connection class 
Author Message
 Please Help -- Problem with either Webservices or my connection class

Hello Everyone,

I have been fighting with this webservice of mine for several days and I
would really appreciate some input.

I was going to attach 4 text files -- instead I have pasted them below my
question area.

 The first is what should be creating a connection class,
The second is a webservice which uses the (open) connection object.
The third is the code behind a button on the default page for my web page.
The fourth is the error message that is created when I press the button.

My first question is : Can my webservice use an open connection object or is
there something that must be set for this to be allowed?

My second question is : Am I using the connection object correctly?

My third question is : What must I do to avoid receiving the SSPI error ?

My fourth question is : Why is there two ".." in the error message?

Thank You in Advance for Your Help,

Ken

_____________________

1_connection class

____________________________________________________________________________
________________________________________________________
using System;
using System.Data.SqlClient;

namespace Services.WSsecurity
{
 /// <summary>
 /// Summary description for Connection.
 /// </summary>

 public class MyConn
 {
  public SqlConnection conn;

  public MyConn()
  {
   // put connection string here
   string connString;
   connString = "Data Source=(local);Initial
Catalog=Northwind;Trusted_Connection=yes";

   conn = new SqlConnection(connString);
   conn.Open();

  }

  public MyConn(string mystr )
  {
   string connString;
   connString = "Data Source=(local);Initial Catalog=" + mystr +
";Trusted_Connection=yes";
   conn = new SqlConnection(connString);
   conn.Open();
  }

  public SqlConnection Connection
  {
   get
   {
    return conn;
   }
  }
 }

Quote:
}

____________________________________________________________________________
________________________________________________________

2_Webservices

____________________________________________________________________________
________________________________________________________

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;

namespace Services.WSsecurity
{
 /// <summary>
 /// Summary description for Service1.
 /// </summary>
 public class Security : System.Web.Services.WebService
 {
  public Security()
  {
   //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

  // WEB SERVICE EXAMPLE
  // The HelloWorld() example service returns the string Hello World
  // To build, uncomment the following lines then save and build the project
  // To test this web service, press F5

//  [WebMethod]
//  public string HelloWorld()
//  {
//   return "Hello World";
//  }

  string myuser ;
  string mypass;
  string mydb;
  public int myint;
  [WebMethod]
  public int getsecurityLevel(string username, string password)
  {

   myuser = username;
   mypass = password;
   myint = (int)  this.SelectCommand2.ExecuteScalar();
   this.SelectCommand.Dispose();
   return myint;
  }

  [WebMethod (MessageName="getsecurityLevel_DB")]
  public  int getsecurityLevel(string username, string password,string db_na
me)
  {

   myuser = username;
   mypass = password;
   mydb = db_name;
   myint = ( int ) this.SelectCommand.ExecuteScalar();
   this.SelectCommand.Dispose();
   return myint;
  }

  private SqlCommand SelectCommand2
  {
   get
   {
    //SqlConnection cn;
    Services.WSsecurity.MyConn cn  = new Services.WSsecurity.MyConn();
    SqlCommand sqlCommand = new SqlCommand("sp_check_password",
cn.Connection  );
    sqlCommand.CommandType = CommandType.StoredProcedure;
    sqlCommand.Parameters.Add("username", SqlDbType.VarChar, 50,myuser);
    sqlCommand.Parameters.Add("Password", SqlDbType.VarChar, 50, mypass);
    return sqlCommand;
   }
  }

  private SqlCommand SelectCommand
  {
   get
   {
    //SqlConnection cn;
     Services.WSsecurity.MyConn  cn  = new Services.WSsecurity.MyConn(mydb);
    SqlCommand sqlCommand = new SqlCommand("sp_check_password",
cn.Connection);
    sqlCommand.CommandType = CommandType.StoredProcedure;
    sqlCommand.Parameters.Add("username", SqlDbType.VarChar, 50, myuser);
    sqlCommand.Parameters.Add("Password", SqlDbType.VarChar, 50, mypass);

    return sqlCommand;

   }
  }
 }

Quote:
}

____________________________________________________________________________
________________________________________________________

3_ button

____________________________________________________________________________
________________________________________________________
private void Btn_Password_Click(object sender, System.EventArgs e)
  {
   try
   {
    if (string.Equals(this.TxtUser.ToString() ,""))
    {
     errorLabel.Visible = true;
     errorLabel.Text = "Please fill in the User Name";
    }
    else if (string.Equals(this.TxtPassword.ToString() ,""))
    {
     errorLabel.Visible = true;
     errorLabel.Text = "Please fill in the Password";
    }
    else
    {
     errorLabel.Visible = false;
     localhost.Security mysecurity = new localhost.Security();
     int mysec;
     //mysec = (int)
mysecurity.getsecurityLevel(TxtUser.Text.ToString(),TxtPassword.Text.ToStrin
g(),"Jobs");
     mysec = (int) mysecurity.getsecurityLevel("Ken","candybar","Jobs");
     if (mysec == 0)
     {
     }
     else if (mysec == 5)
     {
     }
     else if  (mysec == 10)
     {
      this.Btn_GetXML.Visible = true;
      this.Btn_XML.Visible = true;
     }
    }
   }
   catch (Exception se)
   {
    errorLabel.Visible = true;
    errorLabel.Text = se.Message.ToString();
   }
  }

____________________________________________________________________________
________________________________________________________

4_error message

____________________________________________________________________________
________________________________________________________

System.Web.Services.Protocols.SoapException: Server was unable to process
request. ---> System.Data.SqlClient.SqlException: Cannot initialize SSPI
package.
   at System.Data.SqlClient.SqlConnection.Open()
   at Services.WSsecurity.MyConn..ctor(String mystr)
   at Services.WSsecurity.Security.get_SelectCommand()
   at Services.WSsecurity.Security.getsecurityLevel(String username, String
password, String db_name)
   --- End of inner exception stack trace ---
____________________________________________________________________________
________________________________________________________



Mon, 30 May 2005 04:01:40 GMT  
 Please Help -- Problem with either Webservices or my connection class
I'll take a shot at this since it seems you need help NOW  8).

At first glance, I believe you should be looking at your connection string.
From VS (not ASP.NET),

connString = "Data Source=(local);Initial
Catalog=Northwind;Trusted_Connection=yes";

will allow you to access your db server without a username or password
because you use Trusted_Connection=yes.  However, in the context of a
WebService, which runs in the context of ASP.NET, I believe that
Trusted_Connection=yes will not work because the process trying to access
the db now is aspnet_wp.exe, which is not a trusted user by default.

If you can, create a user for your database and pass the username/password
in the connection string.  Remove the Trusted_Connection bit and add
uid=<your username>; pwd=<your password> (I may be wrong on the syntax)

This is probably the simplest way to start.  There are other ways to do
this, but it's a good start.

Now to your questions:
1.  I believe a webservice can access an open connection as you have coded.
You shouldn't need to do anything special.

2.  You appear to be using the connection object properly-ish (again, there
are other ways to handle what you are doing, and may be better than how you
are doing it)

3.  Change your connection string like I mentioned above.  The SSPI error is
throw because of the Trusted_Connection, I'm sure of it

4.  The two dots in the error message is how the constructor (ctor) is
represented in the Error message.  that's probably a simplistic explanation
of it, but right now, that's what my knowledge is limited to.

Try changing the connection string as above and run it again.  And then,
either email me offline or post the results to the group.

Steve


Quote:
> Hello Everyone,

> I have been fighting with this webservice of mine for several days and I
> would really appreciate some input.

> I was going to attach 4 text files -- instead I have pasted them below my
> question area.

>  The first is what should be creating a connection class,
> The second is a webservice which uses the (open) connection object.
> The third is the code behind a button on the default page for my web page.
> The fourth is the error message that is created when I press the button.

> My first question is : Can my webservice use an open connection object or
is
> there something that must be set for this to be allowed?

> My second question is : Am I using the connection object correctly?

> My third question is : What must I do to avoid receiving the SSPI error ?

> My fourth question is : Why is there two ".." in the error message?

> Thank You in Advance for Your Help,

> Ken

> _____________________

> 1_connection class

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________
> using System;
> using System.Data.SqlClient;

> namespace Services.WSsecurity
> {
>  /// <summary>
>  /// Summary description for Connection.
>  /// </summary>

>  public class MyConn
>  {
>   public SqlConnection conn;

>   public MyConn()
>   {
>    // put connection string here
>    string connString;
>    connString = "Data Source=(local);Initial
> Catalog=Northwind;Trusted_Connection=yes";

>    conn = new SqlConnection(connString);
>    conn.Open();

>   }

>   public MyConn(string mystr )
>   {
>    string connString;
>    connString = "Data Source=(local);Initial Catalog=" + mystr +
> ";Trusted_Connection=yes";
>    conn = new SqlConnection(connString);
>    conn.Open();
>   }

>   public SqlConnection Connection
>   {
>    get
>    {
>     return conn;
>    }
>   }
>  }
> }

____________________________________________________________________________
Quote:
> ________________________________________________________

> 2_Webservices

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________

> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Diagnostics;
> using System.Web;
> using System.Web.Services;
> using System.Data.SqlClient;

> namespace Services.WSsecurity
> {
>  /// <summary>
>  /// Summary description for Service1.
>  /// </summary>
>  public class Security : System.Web.Services.WebService
>  {
>   public Security()
>   {
>    //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

>   // WEB SERVICE EXAMPLE
>   // The HelloWorld() example service returns the string Hello World
>   // To build, uncomment the following lines then save and build the
project
>   // To test this web service, press F5

> //  [WebMethod]
> //  public string HelloWorld()
> //  {
> //   return "Hello World";
> //  }

>   string myuser ;
>   string mypass;
>   string mydb;
>   public int myint;
>   [WebMethod]
>   public int getsecurityLevel(string username, string password)
>   {

>    myuser = username;
>    mypass = password;
>    myint = (int)  this.SelectCommand2.ExecuteScalar();
>    this.SelectCommand.Dispose();
>    return myint;
>   }

>   [WebMethod (MessageName="getsecurityLevel_DB")]
>   public  int getsecurityLevel(string username, string password,string
db_na
> me)
>   {

>    myuser = username;
>    mypass = password;
>    mydb = db_name;
>    myint = ( int ) this.SelectCommand.ExecuteScalar();
>    this.SelectCommand.Dispose();
>    return myint;
>   }

>   private SqlCommand SelectCommand2
>   {
>    get
>    {
>     //SqlConnection cn;
>     Services.WSsecurity.MyConn cn  = new Services.WSsecurity.MyConn();
>     SqlCommand sqlCommand = new SqlCommand("sp_check_password",
> cn.Connection  );
>     sqlCommand.CommandType = CommandType.StoredProcedure;
>     sqlCommand.Parameters.Add("username", SqlDbType.VarChar, 50,myuser);
>     sqlCommand.Parameters.Add("Password", SqlDbType.VarChar, 50, mypass);
>     return sqlCommand;
>    }
>   }

>   private SqlCommand SelectCommand
>   {
>    get
>    {
>     //SqlConnection cn;
>      Services.WSsecurity.MyConn  cn  = new

Services.WSsecurity.MyConn(mydb);
Quote:
>     SqlCommand sqlCommand = new SqlCommand("sp_check_password",
> cn.Connection);
>     sqlCommand.CommandType = CommandType.StoredProcedure;
>     sqlCommand.Parameters.Add("username", SqlDbType.VarChar, 50, myuser);
>     sqlCommand.Parameters.Add("Password", SqlDbType.VarChar, 50, mypass);

>     return sqlCommand;

>    }
>   }
>  }
> }

____________________________________________________________________________
Quote:
> ________________________________________________________

> 3_ button

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________
> private void Btn_Password_Click(object sender, System.EventArgs e)
>   {
>    try
>    {
>     if (string.Equals(this.TxtUser.ToString() ,""))
>     {
>      errorLabel.Visible = true;
>      errorLabel.Text = "Please fill in the User Name";
>     }
>     else if (string.Equals(this.TxtPassword.ToString() ,""))
>     {
>      errorLabel.Visible = true;
>      errorLabel.Text = "Please fill in the Password";
>     }
>     else
>     {
>      errorLabel.Visible = false;
>      localhost.Security mysecurity = new localhost.Security();
>      int mysec;
>      //mysec = (int)

mysecurity.getsecurityLevel(TxtUser.Text.ToString(),TxtPassword.Text.ToStrin

- Show quoted text -

Quote:
> g(),"Jobs");
>      mysec = (int) mysecurity.getsecurityLevel("Ken","candybar","Jobs");
>      if (mysec == 0)
>      {
>      }
>      else if (mysec == 5)
>      {
>      }
>      else if  (mysec == 10)
>      {
>       this.Btn_GetXML.Visible = true;
>       this.Btn_XML.Visible = true;
>      }
>     }
>    }
>    catch (Exception se)
>    {
>     errorLabel.Visible = true;
>     errorLabel.Text = se.Message.ToString();
>    }
>   }

____________________________________________________________________________
Quote:
> ________________________________________________________

> 4_error message

____________________________________________________________________________
Quote:
> ________________________________________________________

> System.Web.Services.Protocols.SoapException: Server was unable to process
> request. ---> System.Data.SqlClient.SqlException: Cannot initialize SSPI
> package.
>    at System.Data.SqlClient.SqlConnection.Open()
>    at Services.WSsecurity.MyConn..ctor(String mystr)
>    at Services.WSsecurity.Security.get_SelectCommand()
>    at Services.WSsecurity.Security.getsecurityLevel(String username,
String
> password, String db_name)
>    --- End of inner exception stack trace ---

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________



Mon, 30 May 2005 04:50:30 GMT  
 Please Help -- Problem with either Webservices or my connection class

Hello All,

Well I decided to use my connection class object to create a connection
string instead. Also , I trashed the idea of using SqlConnection and
SqlCommand objects in my Web service, because they just don't work. Instead
I used OleDBConnection and OleDBCommand instead ; now everything works fine.
I think there are some issues which need to be resolved by "M".

Thank You everyone for Your Help,

Ken

Quote:
> Hello Everyone,

> I have been fighting with this webservice of mine for several days and I
> would really appreciate some input.

> I was going to attach 4 text files -- instead I have pasted them below my
> question area.

>  The first is what should be creating a connection class,
> The second is a webservice which uses the (open) connection object.
> The third is the code behind a button on the default page for my web page.
> The fourth is the error message that is created when I press the button.

> My first question is : Can my webservice use an open connection object or
is
> there something that must be set for this to be allowed?

> My second question is : Am I using the connection object correctly?

> My third question is : What must I do to avoid receiving the SSPI error ?

> My fourth question is : Why is there two ".." in the error message?

> Thank You in Advance for Your Help,

> Ken

> _____________________

> 1_connection class

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________
> using System;
> using System.Data.SqlClient;

> namespace Services.WSsecurity
> {
>  /// <summary>
>  /// Summary description for Connection.
>  /// </summary>

>  public class MyConn
>  {
>   public SqlConnection conn;

>   public MyConn()
>   {
>    // put connection string here
>    string connString;
>    connString = "Data Source=(local);Initial
> Catalog=Northwind;Trusted_Connection=yes";

>    conn = new SqlConnection(connString);
>    conn.Open();

>   }

>   public MyConn(string mystr )
>   {
>    string connString;
>    connString = "Data Source=(local);Initial Catalog=" + mystr +
> ";Trusted_Connection=yes";
>    conn = new SqlConnection(connString);
>    conn.Open();
>   }

>   public SqlConnection Connection
>   {
>    get
>    {
>     return conn;
>    }
>   }
>  }
> }

____________________________________________________________________________
Quote:
> ________________________________________________________

> 2_Webservices

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________

> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Diagnostics;
> using System.Web;
> using System.Web.Services;
> using System.Data.SqlClient;

> namespace Services.WSsecurity
> {
>  /// <summary>
>  /// Summary description for Service1.
>  /// </summary>
>  public class Security : System.Web.Services.WebService
>  {
>   public Security()
>   {
>    //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

>   // WEB SERVICE EXAMPLE
>   // The HelloWorld() example service returns the string Hello World
>   // To build, uncomment the following lines then save and build the
project
>   // To test this web service, press F5

> //  [WebMethod]
> //  public string HelloWorld()
> //  {
> //   return "Hello World";
> //  }

>   string myuser ;
>   string mypass;
>   string mydb;
>   public int myint;
>   [WebMethod]
>   public int getsecurityLevel(string username, string password)
>   {

>    myuser = username;
>    mypass = password;
>    myint = (int)  this.SelectCommand2.ExecuteScalar();
>    this.SelectCommand.Dispose();
>    return myint;
>   }

>   [WebMethod (MessageName="getsecurityLevel_DB")]
>   public  int getsecurityLevel(string username, string password,string
db_na
> me)
>   {

>    myuser = username;
>    mypass = password;
>    mydb = db_name;
>    myint = ( int ) this.SelectCommand.ExecuteScalar();
>    this.SelectCommand.Dispose();
>    return myint;
>   }

>   private SqlCommand SelectCommand2
>   {
>    get
>    {
>     //SqlConnection cn;
>     Services.WSsecurity.MyConn cn  = new Services.WSsecurity.MyConn();
>     SqlCommand sqlCommand = new SqlCommand("sp_check_password",
> cn.Connection  );
>     sqlCommand.CommandType = CommandType.StoredProcedure;
>     sqlCommand.Parameters.Add("username", SqlDbType.VarChar, 50,myuser);
>     sqlCommand.Parameters.Add("Password", SqlDbType.VarChar, 50, mypass);
>     return sqlCommand;
>    }
>   }

>   private SqlCommand SelectCommand
>   {
>    get
>    {
>     //SqlConnection cn;
>      Services.WSsecurity.MyConn  cn  = new

Services.WSsecurity.MyConn(mydb);
Quote:
>     SqlCommand sqlCommand = new SqlCommand("sp_check_password",
> cn.Connection);
>     sqlCommand.CommandType = CommandType.StoredProcedure;
>     sqlCommand.Parameters.Add("username", SqlDbType.VarChar, 50, myuser);
>     sqlCommand.Parameters.Add("Password", SqlDbType.VarChar, 50, mypass);

>     return sqlCommand;

>    }
>   }
>  }
> }

____________________________________________________________________________
Quote:
> ________________________________________________________

> 3_ button

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________
> private void Btn_Password_Click(object sender, System.EventArgs e)
>   {
>    try
>    {
>     if (string.Equals(this.TxtUser.ToString() ,""))
>     {
>      errorLabel.Visible = true;
>      errorLabel.Text = "Please fill in the User Name";
>     }
>     else if (string.Equals(this.TxtPassword.ToString() ,""))
>     {
>      errorLabel.Visible = true;
>      errorLabel.Text = "Please fill in the Password";
>     }
>     else
>     {
>      errorLabel.Visible = false;
>      localhost.Security mysecurity = new localhost.Security();
>      int mysec;
>      //mysec = (int)

mysecurity.getsecurityLevel(TxtUser.Text.ToString(),TxtPassword.Text.ToStrin

- Show quoted text -

Quote:
> g(),"Jobs");
>      mysec = (int) mysecurity.getsecurityLevel("Ken","candybar","Jobs");
>      if (mysec == 0)
>      {
>      }
>      else if (mysec == 5)
>      {
>      }
>      else if  (mysec == 10)
>      {
>       this.Btn_GetXML.Visible = true;
>       this.Btn_XML.Visible = true;
>      }
>     }
>    }
>    catch (Exception se)
>    {
>     errorLabel.Visible = true;
>     errorLabel.Text = se.Message.ToString();
>    }
>   }

____________________________________________________________________________
Quote:
> ________________________________________________________

> 4_error message

____________________________________________________________________________
Quote:
> ________________________________________________________

> System.Web.Services.Protocols.SoapException: Server was unable to process
> request. ---> System.Data.SqlClient.SqlException: Cannot initialize SSPI
> package.
>    at System.Data.SqlClient.SqlConnection.Open()
>    at Services.WSsecurity.MyConn..ctor(String mystr)
>    at Services.WSsecurity.Security.get_SelectCommand()
>    at Services.WSsecurity.Security.getsecurityLevel(String username,
String
> password, String db_name)
>    --- End of inner exception stack trace ---

____________________________________________________________________________

- Show quoted text -

Quote:
> ________________________________________________________



Sun, 05 Jun 2005 05:43:24 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. problem with either webservices or my connection class

2. NewBie, webservice error please help

3. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

4. class not defined, basic problem, please help!

5. Please help: Problems with instances of a class

6. Simple WebService problem with .NET - Help!

7. I am not able to see my database class members in class view - Please help

8. Please help!!!!Please help!!!!Please help!!!!

9. CRecordSet class and ODBC connections - Too many connections

10. Problem with either m

11. Problem with either my book or my server.

12. HELP - ODBC connection in console app using MFC classes

 

 
Powered by phpBB® Forum Software