Do you know IQuery.ExecuteUpdate() ?
2009/3/30 Fred F. <[email protected]>
>
> Hi,
>
> I'm currently trying to execute a stored procedure through the
> nhibernate session. I've read in the best practises chapter that I
> shouldn't manage the additional database sessions by myself, but shall
> use the nhibernate session. So I did and I've created the code below.
> Sad but true: For each call of my stored procedure a new database
> session is opened, but won't be closed again although I do explicitly
> try to close and dispose them.
>
> Any hints for me?
> Thanks in advance.
>
> NHibernate Version 2.0.1
>
> Fred F.
>
>
> -----------------------------------------------------------------------------------
> [code]
>
> Dim toReturn As New MyKeyType
>
> Try
>
> Using prov As IConnectionProvider =
> ConnectionProviderFactory.NewConnectionProvider
> (_configuration.Properties)
>
> Dim conn As IDbConnection = prov.GetConnection()
> Dim cmd As IDbCommand = conn.CreateCommand()
>
> cmd.Transaction = conn.BeginTransaction()
>
> cmd.CommandText = "mypackage.mystoredproc"
> cmd.CommandType = CommandType.StoredProcedure
>
> '-- param 1
> Dim param1 As OracleParameter = New OracleParameter
> ("param1", OracleType.VarChar)
> param1.Value = "testparam"
> cmd.Parameters.Add(param1)
>
> '-- param 2 (out parameter)
> Dim outParam As OracleParameter = New OracleParameter
> ("returnparam", OracleType.Cursor)
> outParam.Direction = ParameterDirection.Output
> cmd.Parameters.Add(outParam)
>
> cmd.ExecuteNonQuery()
> cmd.Transaction.Commit()
>
> Dim reader As OracleDataReader = CType
> (cmd.ExecuteReader(), OracleDataReader)
> If Not reader.HasRows Then
> Throw New Exception("Error")
> End If
>
> reader.Read()
>
> '-- parse some data from the reader to the return value
> toReturn.Key1 = Parse(reader, 0)
> toReturn.Key2 = Parse(reader, 1)
>
> cmd.Dispose()
> conn.Close()
> prov.CloseConnection(conn)
>
> End Using
>
> Catch ex As Exception
> Throw New Exception("Error", strTypeName), ex)
> End Try
>
> [/code]
> >
>
--
Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---