DEVBUZZ Homepage SQL procedures in the CDB database??
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | Database

SQL procedures in the CDB database??
Written by Jim Poe  [author's bio]  [read 47530 times]
Edited by Derek

eVB Ver 3.0   

Page 1  Page 2
[Download the code] [Discuss this tutorial]

One disappointing aspect of using ActiveSync's Pocket Access conversion utility is that queries stored in the desktop version of an Access database are not converted. Of course, it's not likely that such a conversion would be very successful anyway since CE databases run a stripped down version of SQL that does not support many Access-specific statements such as accessing the value of a control on an Access form. This leaves two options for specifying queries in eVB applications that use CDB files for storing data:

1) Hard code SQL statements in the eVB code or
2) Use the CDB system table MSysProcs which stores procedures in the CDB file itself.

In this tutorial, I'll investigate the second approach and look at how to:

  • add stored procedures to a CE database
  • execute stored procedures with ADOCE
  • create parameterized stored procedures

MSysProcs Table Definition

In the screen shot below, I've modified the Database Viewer sample application (included in the Embedded Visual Tools SDK) to display the details of the MSysProcs table.

As you can see, MSysProcs contains two fields, ProcName and SQLText. ProcName is the name of the stored procedure and SQLText is the command that will be executed when the stored procedure is called. The ADOCE documentation cites a few limitations that apply to all SQL statements, and therefore, to any stored procedures added to MSysProcs (see the "SQL Statement Syntax" section of the help file for more information):

  • Procedure names are limited to 31 characters.
  • SQL statements are restricted to 2,048 characters.
  • Up to three fields can be sorted in an ORDER BY clause.
  • Statements are case sensitive when assigning data to a field
  • Query results are limited to 64 KB
  • An empty SQL string generates the DB_E_NOCOMMAND error value

Despite the fact that CE SQL statements have these requirements, the MSysProcs table does not have any constraints to prevent you from breaking these rules, so use caution when adding stored procedures or you might end up with some unexpected results. For example, it's perfectly legal to insert records into MSysProcs that have the same ProcName. I tested this and found that if you add two procedures with the same ProcName and attempt to execute that ProcName, ADOCE will simply choose the first procedure in MSysProcs with that name. MSysProcs will also allow you to insert records without a value for ProcName and/or without a value for SQLText. However, you'll get an error message, if you try to execute a procedure without a value for these fields.

Using MSysProcs

Now that you've seen the structure of MSysProcs, take a look at these pretty straightforward examples for retrieving, adding, deleting, and executing stored procedures:

'Retrieve stored procedures:
' open connection code omitted
Set Rs = CreateObject("ADOCE.Recordset.3.0")
Rs.Open "MSysProcs", Conn, adOpenStatic, adLockReadOnly, adCmdTableDirect

'Add a stored procedure:
' open connection code omitted
Set Rs = CreateObject("ADOCE.Recordset.3.0")
Rs.Open "MSysProcs", Conn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
Rs.AddNew
Rs.Fields("ProcName") = ProcName
Rs.Fields("SQLText") = SQLText
Rs.Update

'Delete a stored procedure:
' open connection code omitted
Conn.Execute "DELETE FROM MSysProcs WHERE ProcName = '" & ProcName & "'"

'Execute a stored procedure:
' open connection code omitted
Rs.Open ProcName, Conn, adOpenForwardOnly, adLockReadOnly, adCmdStoredProc

Next Page 

Back to Database | [Article Index]

 

Back to the top of the page.
Chris De Herrera's Windows CE Website Windows CE News & Information Source
Copyright ©2000-2007 by DEVBUZZ.COM, Inc., NJ. USA.MSDEVELOP