[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Re: Problem using connection object and permissions

Ken

12/31/2002 12:03:00 AM

Hello Peter,

Here are both code pieces
1) To create a connection string,because I could not create an open
Connection object or a connection object.

2) To use the connection string to point ot more than one database.

P.S. I am following examples on using an XML document to use as a
DataSource for a datagrid. However , I am only recieving the last row.
Any ideas?

Thank You for Your Help,
Ken
------------------------------------
MY CONNECTION STRING Class
------------------------------------
using System;
using System.Data.SqlClient;





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

public class MyConn
{
//public SqlConnection conn;
public string myconnstr;
public MyConn()
{
// put connection string here
//string connString;
myconnstr = "Provider=SQLOLEDB;Data Source=(local);Initial
Catalog=Northwind;Trusted_Connection=yes;connection timeout=0";

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

}

public MyConn(string mystr )
{
//string connString;
myconnstr = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog="
+ mystr + ";Trusted_Connection=yes;connection timeout=0";
//conn = new SqlConnection(connString);
//conn.Open();
}

public string Connection
{
get
{
return myconnstr;
}
}
}
}

------------------------------------
MY XML WEB SERVICE
------------------------------------
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;
using System.Data.OleDb;

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

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

private OleDbCommand SelectCommand2
{
get
{
//SqlConnection cn;
Services.WSsecurity.MyConn cn = new Services.WSsecurity.MyConn();
//cn.Connection is now just a connection string
//SqlConnection conn = new SqlConnection(cn.Connection);
//conn.Open();
//SqlCommand sqlCommand = new SqlCommand("sp_check_password", conn
);
//sqlCommand.CommandType = CommandType.StoredProcedure;
//sqlCommand.Parameters.Add("@username", SqlDbType.VarChar,
50,myuser);
//sqlCommand.Parameters.Add("@Password", SqlDbType.VarChar, 50,
mypass);

OleDbConnection myConnect7;
myConnect7 = new OleDbConnection(cn.Connection);
myConnect7.Open();
OleDbCommand _dbken;

_dbken = new OleDbCommand();
_dbken.Connection = myConnect7;
_dbken.CommandTimeout = 0;

_dbken.CommandText = "sp_check_password";
_dbken.CommandType = CommandType.StoredProcedure;
_dbken.Parameters.Add("@username",OleDbType.VarChar,50).Value =
myuser ;
_dbken.Parameters.Add("@Password", OleDbType.VarChar, 50).Value =
mypass;

return _dbken;
}
}

private OleDbCommand SelectCommand
{
get
{
//SqlConnection cn;
Services.WSsecurity.MyConn cn = new
Services.WSsecurity.MyConn(mydb);
//cn.Connection is now just a connection string
//SqlConnection conn = new SqlConnection(cn.Connection);
//conn.Open();
//SqlCommand sqlCommand = new SqlCommand("sp_check_password", conn
);
//sqlCommand.CommandType = CommandType.StoredProcedure;
//sqlCommand.Parameters.Add("@username", SqlDbType.VarChar,
50,myuser);
//sqlCommand.Parameters.Add("@Password", SqlDbType.VarChar, 50,
mypass);

OleDbConnection myConnect7;
myConnect7 = new OleDbConnection(cn.Connection);
myConnect7.Open();
OleDbCommand _dbken;

_dbken = new OleDbCommand();
_dbken.Connection = myConnect7;
_dbken.CommandTimeout = 0;

_dbken.CommandText = "sp_check_password";
_dbken.CommandType = CommandType.StoredProcedure;
_dbken.Parameters.Add("@username",OleDbType.VarChar,50).Value =
myuser ;
_dbken.Parameters.Add("@Password", OleDbType.VarChar, 50).Value =
mypass;

return _dbken;

}
}
}
}



*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!
1 Answer

(Peter Wu [MS])

12/31/2002 7:07:00 AM

0

: Here are both code pieces
: 1) To create a connection string,because I could not create an open
: Connection object or a connection object.
:
: 2) To use the connection string to point ot more than one database.

Thanks for the source code segment. :)

: P.S. I am following examples on using an XML document to use as a
: DataSource for a datagrid. However , I am only recieving the last row.
: Any ideas?

Can you direct me to those examples, please? Do you load the XML content
into a DataSet and bind the DataGrid to the DataSet? If yes, you may want
to read the following KB article.

311566 HOW TO: Read XML Data into a DataSet by Using Visual C# .NET
http://support.microsoft.com/...


Hope this helps.

--
Peter Wu
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.