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
- Next message: Nick Malik: "Re: Encrypting a public Key"
- Previous message: Nick Malik: "Re: .NET Framework not installed message"
- In reply to: Parco: "Re: Can i pass a SqlConnection object with opened connection to a method/function as a parameter?"
- Messages sorted by: [ date ] [ thread ]
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
... 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)
... 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)
... 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)
... you have ALL your users sharing one connection. ... Public Shared Function GetServerAs String ... Dim theServer As String ...
(microsoft.public.dotnet.framework.aspnet)
... 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)