Skip to main content

developerWorks >  Information Management  >  Forums  >  IBM DB2 Express Forum  >  developerWorks

DB2 STORED NPROCEDURES    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
This question is not answered.

Permlink Replies: 5 - Pages: 1 - Last Post: Nov 10, 2009 3:21 AM Last Post By: DB2Newbie_VB.NET Threads: [ Previous | Next ]
DB2Newbie_VB.NET

Posts: 8
Registered: Nov 05, 2009 08:43:17 AM
DB2 STORED NPROCEDURES
Posted: Nov 05, 2009 05:45:18 PM
 
Click to report abuse...   Click to reply to this thread Reply
Hello. I am trying to learn a bit about DB2 EXPRESS-C(I've got the latest version downloaded 2 weeks ago). So far I have managed to create the SAMPLE database that comes as part of the First Steps. Now using control centre I would like to get the size of the database. What i would like to achieve is calling a command(hopefully SQL Stored procedure) that would return the information in a data table. Eventually i would like to call this stored procedure from a simple .NET application and get all the relevant space information in a data table.
ianbjor

Posts: 47
Registered: Mar 14, 2006 10:48:40 AM
Re: DB2 STORED NPROCEDURES
Posted: Nov 06, 2009 03:57:56 AM   in response to: DB2Newbie_VB.NET in response to: DB2Newbie_VB.NET's post
 
Click to report abuse...   Click to reply to this thread Reply
See SYSPROC.GET_DBSIZE_INFO -- it does what you're looking for.
DB2Newbie_VB.NET

Posts: 8
Registered: Nov 05, 2009 08:43:17 AM
Re: DB2 STORED NPROCEDURES
Posted: Nov 06, 2009 09:39:07 AM   in response to: ianbjor in response to: ianbjor's post
 
Click to report abuse...   Click to reply to this thread Reply
First off i'm keen to get the amount of database space using a very simple .NET functions. Not using Control Centre.
GET_DBSIZE_INFO, when executed successfully updates a table SYSTOOLS.STMG_DBSIZE_INFO with the appropriate space information. In my opinion to get what i need using my ..NET application I require 2 steps

Step 1: Execute GET_DBSIZE_INFO using a function written in .NET
Step 2: Read the SYSTOOLS.STMG_DBSIZE_INFO table for updated information using a function written in .NET

Now as relates Step 1 the function i've written is shown below, It basically calls the GET_DBSIZE_INFO stored procedure on a DB2 DATABASE CONNECTION

Public Function ExecDBSizeInfo() As Integer Implements DBInfoInterface.IGetDBSpaceInfo.ExecDBSizeInfo
Try
Dim Conn As New DB2Connection
Dim val As Integer

Dim param As New DB2Parameter("Input0", DB2Type.Char)
param.Value = "?"
Dim param1 As New DB2Parameter("Input1", DB2Type.Char)
param1.Value = "?"
Dim param2 As New DB2Parameter("Input2", DB2Type.Char)
param2.Value = "?"
Dim param3 As New DB2Parameter("Input3", DB2Type.Integer)
param3.Value = "0"

Dim db2Params As DB2Parameter() = {param, param1, param2, param3}

Conn.ConnectionString = DB2Helper.DB2Helper.ConnString
val = DB2Helper.DB2Helper.ExecuteNonQuery(Conn, "SYSPROC.GET_DBSIZE_INFO", db2Params)
Conn.Close()
Conn.Dispose()
ExecDBSizeInfo = val
Return ExecDBSizeInfo

Catch ex As DB2Exception
Throw ex
End Try

End Function

If the function executes successfully I should get 0 (zero) as the result of the funtion. Currently i get
-1(negative one),meaning the SYSPROC.GET_DBSIZE_INFO is not executing successfully.

Can anyone help me understand what is going wrong?
ianbjor

Posts: 47
Registered: Mar 14, 2006 10:48:40 AM
Re: DB2 STORED NPROCEDURES
Posted: Nov 06, 2009 05:52:48 PM   in response to: DB2Newbie_VB.NET in response to: DB2Newbie_VB.NET's post
 
Click to report abuse...   Click to reply to this thread Reply
The first 3 parameters for GET_DBSIZE_INFO are OUT parameters -- the stored procedure returns values for these, so you need to declare them as OUT parameters and associate variables in your code with these.

I'm not a .NET developer, but if you look at the sample code (SpClient.vb - specifically the CallOutLanguage function) you should get a good idea of how to do this.
DB2Newbie_VB.NET

Posts: 8
Registered: Nov 05, 2009 08:43:17 AM
Re: DB2 STORED NPROCEDURES
Posted: Nov 06, 2009 08:36:49 PM   in response to: ianbjor in response to: ianbjor's post
 
Click to report abuse...   Click to reply to this thread Reply
No joy so far

I've tried everything

Public Function ExecDBSizeInfo() As Integer Implements DBInfoInterface.IGetDBSpaceInfo.ExecDBSizeInfo
Try
Dim Conn As New DB2Connection
Dim val As Integer

Dim param As New DB2Parameter("Input0", DB2Type.Timestamp)
param.Value = "?"
Dim param1 As New DB2Parameter("Input1", DB2Type.BigInt)
param1.Value = "?"
Dim param2 As New DB2Parameter("Input2", DB2Type.BigInt)
param2.Value = "?"
Dim param3 As New DB2Parameter("Input3", DB2Type.Integer)
param3.Value = "0"

Dim db2Params As DB2Parameter() = {param, param1, param2, param3}

Conn.ConnectionString = DB2Helper.DB2Helper.ConnString
val = DB2Helper.DB2Helper.ExecuteNonQuery(Conn, "SYSPROC.GET_DBSIZE_INFO", db2Params)
Conn.Close()
Conn.Dispose()
ExecDBSizeInfo = val
Return ExecDBSizeInfo

Catch ex As DB2Exception
Throw ex
End Try

End Function

This did not work the function returns -1...so i tried

Public Function ExecDBSizeInfo() As Integer Implements DBInfoInterface.IGetDBSpaceInfo.ExecDBSizeInfo
Try
Dim Conn As New DB2Connection
Dim val As Integer

Dim param As New DB2Parameter("Input0", DB2Type.Timestamp)
param.Value = "?"
param.direction=parameterdirection.output
Dim param1 As New DB2Parameter("Input1", DB2Type.BigInt)
param1.Value = "?"
param.direction=parameterdirection.output
Dim param2 As New DB2Parameter("Input2", DB2Type.BigInt)
param2.Value = "?"
param.direction=parameterdirection.output
Dim param3 As New DB2Parameter("Input3", DB2Type.Integer)
param3.Value = "0"
param.direction=parameterdirection.Input

Dim db2Params As DB2Parameter() = {param, param1, param2, param3}

Conn.ConnectionString = DB2Helper.DB2Helper.ConnString
val = DB2Helper.DB2Helper.ExecuteNonQuery(Conn, "SYSPROC.GET_DBSIZE_INFO", db2Params)
Conn.Close()
Conn.Dispose()
ExecDBSizeInfo = val
Return ExecDBSizeInfo

Catch ex As DB2Exception
Throw ex
End Try

End Function

Still NO SUCCESS, Function returns -1, I even tried removing the param.value bits, and still no success. Slowly tearing my hair out. Looked at the spClient.VB and i'm reasonably sure they are doing much the same as me, yet i can't figure out why mine doesn't work. If anyone has any .NET experience using stored procedures especially system stored procedures I'd like to know what i'm doing wrong

Can anyone help me understand what is going wrong?

If the function executes successfully I should get 0 (zero) as the result of the funtion. Currently i get
-1(negative one),meaning the SYSPROC.GET_DBSIZE_INFO is not executing successfully.

Can anyone help me understand what is going wrong?

DB2Newbie_VB.NET

Posts: 8
Registered: Nov 05, 2009 08:43:17 AM
Re: DB2 STORED NPROCEDURES
Posted: Nov 10, 2009 03:21:41 AM   in response to: DB2Newbie_VB.NET in response to: DB2Newbie_VB.NET's post
 
Click to report abuse...   Click to reply to this thread Reply
I think the following actually works

Public Function ExecDBSizeInfo() As Integer Implements DBInfoInterface.IGetDBSpaceInfo.ExecDBSizeInfo
Try
Dim Conn As New DB2Connection
Dim val As Integer

Dim param As New DB2Parameter("Input0", DB2Type.Timestamp)
Dim param1 As New DB2Parameter("Input1", DB2Type.BigInt)
Dim param2 As New DB2Parameter("Input2", DB2Type.BigInt)
Dim param3 As New DB2Parameter("Input3", DB2Type.Integer)
param3.Value = "0"

Dim db2Params As DB2Parameter() = {param, param1, param2, param3}

Conn.ConnectionString = DB2Helper.DB2Helper.ConnString
val = DB2Helper.DB2Helper.ExecuteNonQuery(Conn, "SYSPROC.GET_DBSIZE_INFO", db2Params)
Conn.Close()
Conn.Dispose()
ExecDBSizeInfo = val
Return ExecDBSizeInfo

Catch ex As DB2Exception
Throw ex
End Try

End Function

Now the return value is -1 but i believe that when you perform a storedprocedure using executenonquery, the return value is -1, by default. I did a little googling and saw the following comment

http://www.codeproject.com/Messages/3125109/SqlCommands-ExecuteNonQuery-always-return-1.aspx
For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

If anyone can expand or offer an alternative viewpoint i'll consider the question as answered in 2 days

 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums