Re: Can i pass a SqlConnection object with opened connection to a method/function as a parameter?

From: Nick Malik (nickmalik_at_hotmail.nospam.com)
Date: 10/03/04


Date: Sun, 03 Oct 2004 06:52:32 GMT

Looks functional.
Byzantine.
But functional.

I agree with Richard... set up your command object to execute a stored
procedure and create the parameters individually.

Then, at least, if you are getting a casting error from one of the other
methods in your long concatenated (rather tortured) string, you will be able
to tell which one! I also agree that the problem is probably either in the
DataTools.EscapeMask method (a static method, apparently), or the
GetLoginUser method. It probably has nothing to do with the SqlConnection
object.

--- Nick

"Parco" <parco@nowlover.com> wrote in message
news:%23KKSDiGqEHA.3668@TK2MSFTNGP15.phx.gbl...
> This is my assembly object's method:
>
>
> public static bool CheckPermission(SqlConnection objconn, string
> permissionitem, string itemname, string loginuser)
> {
> SqlCommand objcmd = new SqlCommand("EXEC [checkpermission]
> @permissionitem = '" + DataTools.EscapeMask(permissionitem) + "',
@itemname
> = '" + DataTools.EscapeMask(itemname) + "', @loginacc = '" +
> DataTools.EscapeMask(GetLoginUser(loginuser, LoginAccount)) + "',
@logincus
> = '" + DataTools.EscapeMask(GetLoginUser(loginuser, LoginCustomer)) + "'",
> (SqlConnection)objconn);
> short intresult = (short)objcmd.ExecuteScalar();
> bool checkresult;
>
> if(intresult > 0)
> {
> checkresult = true;
> }
> else
> {
> checkresult = false;
> }
>
> objcmd.Dispose();
>
> return checkresult;
> }
>
>
> This is my code of ASP.NET page which using the method:
>
>
> SqlConnection objconn = new
> SqlConnection(ConfigurationSettings.AppSettings["connstr_webhosting"]);
> objconn.Open();
>
> bool permited = (bool)CPanel.CheckPermission(objconn, "systeminfo",
> "yes", User.Identity.Name);
>
>
> How to solve it?
>
>
> "Richard Blewett [DevelopMentor]" <richardb@develop.com> ¦b¶l¥ó
> news:uiz4%23tFqEHA.2900@TK2MSFTNGP12.phx.gbl ¤¤¼¶¼g...
> > This should be fine, can you show us the code of how you pass the
> connection and what you do with it when you get it
> >
> > Regards
> >
> > Richard Blewett - DevelopMentor
> > http://staff.develop.com/richardb/weblog
> >
> >
>
nntp://news.microsoft.com/microsoft.public.dotnet.framework/>
> >
> > Can i pass a SqlConnection object with opened connection to a
> > method/function as a parameter?
> >
> > For example, i need a method to process something from ASP.NET by a
.NET
> > assembly, but i don't want to connect a new connection anymore and just
> use
> > the existed opened sqlconnection object to do it and pass the object to
> the
> > method.
> >
> > that is a static method.
> > but iis told me an exception error that is System.InvalidCastException
> >
> >
> > why?
> > and how to solved?
> > or how to do it?
> >
> >
> >
> > ---
> > Incoming mail is certified Virus Free.
> > Checked by AVG anti-virus system (
http://www.grisoft.com).
> > Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004
> >
> >
> >
> > [microsoft.public.dotnet.framework]
>
>



Relevant Pages

  • Re: Getting connectionstring from web.config when in a dll
    ... I use an SqlConnection object ... I didn't see you're talking about connection strings. ... string connectionString = c.ConnectionString; ... Dim connectionStrings As ConnectionStringSettingsCollection = ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ADO connections question
    ... Function CreateADOObjects(ConnectionString as string) ... you'll see this error if the connection has not been ... I have a specific login form that calls the dbLogin function as shown ... Dim strCriteria As String ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Nochmals Treeview
    ... private void button1_Click(object sender, System.EventArgs e) { ... private void TabelleAnlegen(string strDBPfad, string strDB, string strTabellenName){ ... OleDbConnection connection = new OleDbConnection; ... OleDbCommand command = new OleDbCommand; ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: ExecuteReader requires an open and available Connection.
    ... you have ALL your users sharing one connection. ... Public Shared Function GetServerAs String ... Dim theServer As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Error using Login control ASP.NET App_Data Folder
    ... the UserInstance type of connection string is for SQLEXPRESS only and is ... Server Management Studio and use a standard connection ... An error has occurred while establishing a connection to the server. ... SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, ...
    (microsoft.public.dotnet.framework.aspnet)