Full Download SQL Server CE Database Development With The NET Compact Framework 1st Edition Rob Tiffany (Auth.) PDF
Full Download SQL Server CE Database Development With The NET Compact Framework 1st Edition Rob Tiffany (Auth.) PDF
https://ebookultra.com
https://ebookultra.com/download/sql-server-ce-
database-development-with-the-net-compact-
framework-1st-edition-rob-tiffany-auth/
https://ebookultra.com/download/the-definitive-guide-to-the-net-
compact-framework-1st-edition-larry-roof/
ebookultra.com
https://ebookultra.com/download/programming-microsoft-sql-
server-2000-with-microsoft-visual-basic-net-1st-edition-edition-rick-
dobson/
ebookultra.com
https://ebookultra.com/download/designing-sql-server-2000-databases-
for-net-enterprise-servers-1st-edition-robert-a-patton/
ebookultra.com
https://ebookultra.com/download/microsoft-sql-server-2012-t-sql-1st-
edition-tom-coffing/
ebookultra.com
Microsoft SQL Server 2008 Administration with Windows
PowerShell 1st Edition Ananthakumar Muthusamy
https://ebookultra.com/download/microsoft-sql-
server-2008-administration-with-windows-powershell-1st-edition-
ananthakumar-muthusamy/
ebookultra.com
https://ebookultra.com/download/sql-server-t-sql-recipes-4th-edition-
jason-brimhall/
ebookultra.com
https://ebookultra.com/download/practical-database-programming-with-
visual-basic-net-second-edition-ying-baiauth/
ebookultra.com
https://ebookultra.com/download/essential-sql-on-sql-server-2008-1st-
edition-dr-sikha-bagui/
ebookultra.com
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN 978-1-59059-119-2 ISBN 978-1-4302-0785-6 (eBook)
DOI 10.1007/978-1-4302-0785-6
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an "as is" basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
To Cathy, Caroline, Nicholas, and Michael.
You're everything I've ever wanted or needed in this world.
Contents at a Glance
Foreword ................................................................................................................. xvii
About the Author ............................................................................................... xxi
About the Technical Reviewer .................................................................. xxiii
Acknowledgments ................................................................................................... xxv
Introduction .................................................................................................... xxvii
Chapter 1 Getting Started ...................................................................... 1
Chapter 2 ADO.NET .....................................................................................29
Chapter 3 Query Analyzer .................................................................. ,...51
Chapter 4 SQL Server CE Data Definition Language ................... 69
Chapter 5 Metadata ................................................................................. 107
Chapter 6 Data Manipulation Language .......................................... 139
Chapter 7 Operator Reference ........................................................... 181
Chapter 8 Function Reference ........................................................... 227
Chapter 9 Remote Data Access ...........................................................311
Chapter 10 Replication ...........................................................................361
Appendix The •NET Compact Framework Class Libraries ....... 395
Index .........................................................................................................................433
v
Contents
Foreword .......................................................................................... xvii
About the Author ........................................................................ xxi
About the Technical Reviewer ........................................... xxiii
Acknowledgments ............................................................................xxv
Introduction ............................................................................. xxvii
vii
Contents
Namespaces ......................................................................................30
System.Data ................................................................................. 30
System.Data.Common ............................................................... 30
System.Data.SqlClient ................................................................ 30
System.Data.SqlServerCe ........................................................... 31
The SqlCeConnection Class .....................................................31
Error Handling ............................................................................ 34
The SqlCeCommand Class ............................................................36
Parameterized Queries ............................................................... 38
Transactions ................................................................................ 40
The SqlCeDataReader Class .....................................................43
The SqlCeDataAdapter Class ...................................................46
Conclusion ......................................................................................49
viii
Contents
ix
Contents
X
Contents
xi
Contents
IN ................................................................................................ 218
LIKE ............................................................................................ 219
NOT ............................................................................................ 221
OR ............................................................................................... 222
Unary ............................................................................................... 224
+ (Positive) ................................................................................. 224
-(Negative) ................................................................................ 225
xii
Contents
xiv
Contents
XV
Foreword
WELCOME TO SQL Server CE Database Development with the .NET Compact
Framework! Back in 1998, I moved off of working on the Jet database engine and
started investigating what was to become Microsoft SQL Server Windows CE
Edition. There was a lot of excitement behind working on a Vl product and
building a new team that was to tackle an area that Microsoft had not yet
embraced. Of course, with all of this came some incredible challenges to create a
robust database to work in the confines of a different OS that had very limited CPU
and RAM resources. I distinctly remember waking up at night, worrying how we
would ever get a database engine to initialize, let alone have good performance on
a MIPS 48 MHz CPU with 16MB total RAM! On top of that, we still had to get man-
agement approval and contend with the fact that we were the last of the "big"
database vendors to come to market for the mobile space.
For the Vl product, we had some design goals that would differentiate us from
the competition in the mobile database arena. First, we decided that being an in-
process DLL would be a competitive advantage over the embedded database and
server model in terms of having tight integration with eMbedded Visual Tools.
Second, we decided that we had to have a very strong sync model, as we believed
our customer base was primarily disconnected. Third, we knew that we had to be
very competitive in performance against our competitors, even though we would
provide more features in a larger footprint. Finally, we knew that we had to have a
very efficient QP that could come up with good query plans, even with limited
CPU power.
As part of any Microsoft project, the team needed to investigate all possibil-
ities before starting on the project and doing the Bill G review. This meant
investigating all angles on how to create a small but still feature-rich database
engine. We looked at everything from buying technology, to porting native SQL
Server, to using existing technology, to starting from scratch. Amazingly, the first
release was a combination of everything that eventually made the SQL Server CE
product.
As is the case with any Vl product, there was a lot of blood, sweat, and tears.
Big features had to be cut because of time constraints (having a componentized
engine was one feature that was hard to cut), and there were a host of inner team
dependencies. It certainly didn't help that the tools (eMbedded Visual Tools) were
in Vl mode and SQL Server 2000 was in beta. Nothing is as challenging as having
every component that the product relies on also be in beta. This led to many inter-
esting challenges, one being when a group of us stayed up for three straight days
trying to get a demo to work for the Windows DNA 2000 Readiness Conference. It's
amazing, when an objective needs to be achieved, how sleep can become irrel-
evant and one can watch cars come and go from the adjacent parking garage three
times straight! Even with all the all-nighters and 14+-hourwork days, the team
xvii
Foreword
pulled together and launched the Vl.O version of the product in October 2000 with
Nabisco for their "cookies and crackers" direct store delivery application.
Amazingly, the Vl.O project didn't have an internal code name, something that
never happens at Microsoft. We got with the times for our Vl.l release and formed
an official committee to come up with a set of code names that would define the
product future releases. We determined that beaches should be the theme, and
Vl.l was christened "Pebble."
We then focused our sights on V2.0, code-named Daytona, and concentrated
primarily on improving the developer experience from eMbedded Visual Tools to
VS .NET and integration with the super cool functionality that came with .NET CE
Again, the whole dependency of other products caused us some strain and forced
us to ship the product twice, once for eMbedded Visual Tools on Sept 19, 2002, and
then again with VS .NET 2003 onAprill9, 2003.
Currently we are working on our next release of SQL Server CE, code named
Laguna, and we have an incredibly valuable set of features and functionality.
Even working at a technology company, I am still amazed at how fast tech-
nology improves. Since the inception of SQL Server CE, the CPU speeds have
dramatically increased from the days of the MIPS 48 MHz PPC device to the latest
Intel XScale PXA255 running at 400 MHz, with a data bus that runs twice the speed
of the previous XScale device. The OS in Pocket PC 2003 has moved from the 3.0
code base ofWindows CE .NET to a 4.2 code base, which among many things has
introduced significant performance improvements and the removal of the 64MB
RAM limitation. Most importantly has been the widespread adoption and stan-
dardization of wireless data protocols. GPRS has finally caught on with Europe and
has widespread deployment in the U.S., and the latest generation of COMA, pro-
viding over lOOKB throughput speeds, has dramatically increased the options
available to developers to deploy truly interesting mobile applications. The
exciting mobile applications that come from this and tight integration of wireless
data into the device is something I still find amazing.
What all of these technology advances have done is increased the widespread
adoption of mobile databases, especially SQL Server CE. We now have a large
number of successful corporate rollouts, with many customers rolling out large
deployments of devices. For example, one customer will have a 90,000-device
deployment.
With all of this technology and large deployments, one of the things that I do
hear from customers is "When is a book on SQL Server CE coming out?" I'm very
happy to say that SQL Server CE Database Development with the .NET Compact
Framework is the first book of its kind to focus on SQL Server CE, data access to
SQL Server CE, and synchronization with SQL Server 2000. This lends credence to
the increased growth of mobile devices in both the consumer and corporate space.
Rob's book does a great job of covering all the basics that a developer would need
xviii
Foreword
xix
About the Author
Rob Tiffany is cofounder and chief technology officer of Hood
Canal Systems, where he's focused on providing exceptional
wireless and handheld products and solutions for his clients.
In addition, Rob is also a speaker, editor, columnist, and
author of articles that have appeared in a variety of trade mag-
azines, including Java Developer's Journal and Visual Basic
Developer, on topics ranging from PersonalJava to wireless
development. SQL Server CE Database Development with the
.NET Compact Framework is Rob's second book to be pub-
lished by Apress. Rob's first book, Pocket PC Database Development with eMbedded
Visual Basic, is still popular with eVB programmers. You can contact Rob at
[email protected].
xxi
About the
Technical Reviewer
Darren Flatt is the cofounder and chief operating officer of Hood Canal Systems.
Darren's current focus is determining how to best leverage mobile technology in
the enterprise. Darren has participated in startup ventures with focuses ranging
from enterprise network management software to consulting services. While
Darren has a business degree, he can code with the best of them. You can contact
Darren at darren. flatt@hoodcanalsystems. com.
xxiii
Acknowledgments
To THE DREAM TEAM atApress, Gary Cornell, Dan Appleman, and Karen Watterson,
thanks for all your support over the years. Back when you gave me the opportunity
to write my first book, Apress was the little publishing company that could. Apress
isn't little anymore.
To the .NET Compact Framework and SQL Server CE teams at Microsoft, the
next phase of the Information Age belongs to you. The wires are gone and the com-
puters have gotten a lot smaller.
XXV
Introduction
Remembering 9/11
THE TRAGIC EVENTS of September 11, 2001, have affected everyone very deeply.
Seeing those airplanes fly into the '!Win Towers was almost surreal. In utter shock,
I watched the World Trade Center collapse and witnessed thousands of people
running and screaming. Until that moment, I thought something of this mag-
nitude only happened in science fiction movies, when Earth found herself on the
verge of extinction at the hands of an alien race. I remember thinking that this
couldn't be happening; my denial was probably coming from that part of the
human psyche that prevents the brain from being overwhelmed when faced with a
previously unimaginable horror. Like many people, I was at the office, in a sky-
scraper, with my coworkers, watching the events unfold on television. I remember
a strange silence in the office; I remember a common look of disbelief on the faces
of my friends; I remember looking out the window and noticing an eerily empty
sky once the president had cleared the U.S. airspace of commercial aircraft.
xxvii
Introduction
xxviii
Introduction
Security. Intelligent software agents can then mine this data in order to connect
the dots and present the president with a more accurate daily threat assessment.
xxix
Introduction
Chapter Summaries
In order to get a quick glimpse of what's to come in this book, I've included brief
summaries of each chapter. As you will see, this book takes you from the ground
floor of learning how to use the Smart Device Extensions, to teaching you about
ADO.NET, and then diving into the inner workings of SQL Server CE 2.0.
Chapter 2: ADO.NET
In this chapter, you'll see which .NET Compact Framework classes are needed to
connect to and manipulate SQL Server CE databases. You'll examine data pro-
viders as well as all the nuances of both connected and disconnected database
access.
XXX
Introduction
Chapter 5: Metadata
In this chapter, you'll learn how to view database objects and their metadata using
the SQL Server CE Information Schema views. Once you've completed this
chapter, you'll no longer need to use Query Analyzer to view the data structures
you've created with DOL.
xxxi
Introduction
xxxii
CHAPTER 1
Getting Started
IN OUR LAST EPISODE, back in the 2000-2001 time frame, I described how we
were entering a new phase of computing that would be dominated by small,
handheld devices designed to make your life easier. The dynamic duo of
eMbedded Visual Basic (eVB) and Pocket Access seemed like a godsend to the
millions ofVisual Basic and Access programmers who would be instantly pro-
ductive in this familiar environment. With old friends like ActiveX controls and
ADO along for the ride, a new wave of powerful Pocket PC 2000 applications would
storm onto the scene. With handheld devices containing 32MB of RAM running at
speeds of over 200 MHz, I always found it amusing when Microsoft told us eVB
programmers that we were working in a severely constrained environment. Did
everybody forget that in the early '90s we were building similar Windows applica-
tions using Visual Basic 3.0 and Access 2.0 with only 4MB of RAM available to us?
As we fast-forward to 2003, handheld devices are everywhere, and they're more
powerful than ever. That being said, your 400 MHz XScale Pocket PC with 64MB of
RAM, a 256MB SD card, and an 802.llx compact flash card is still considered a
resource-constrained device <g>. I hope the true embedded programmers who
are slinging just a few KBs of C code and burning EPROMs don't feel slighted. Oh
well, memory and processors are now small and cheap and that's why smart
devices of all kinds are taking over the market and even outselling PCs.
1
Chapter 1
with the .NET Compact Framework is SQL Server CE 2.0. Just when you thought
you were going to get an upgrade to the Pocket Access (cdb) database you've been
using all these years, Microsoft decides to cram their server database into a con-
strained device and allows it to work with the .NET Compact Framework via
ADO.NET. SQL Server CE is an amazing database that runs in-process as a DLL
with your .NET Compact Framework application and is a giant leap forward over
Pocket Access. Believe it or not, SQL Server CE shares many of the same features as
SQL Server 2000. Some of these features include the following:
• Query Analyzer
• The union operator (plus 30 more operators where that came from)
System Requirements
As I mentioned previously, .NET Compact Framework applications are created
with Visual Studio .NET 2003. This is possible through the use of a Visual Studio
Integration Package (VSIP) that plugs into Visual Studio. This VSIP is called Smart
Device Extensions and allows you to target Pocket PC and Windows CE .NET
devices.
2
Getting Started
Development
The requirements to create .NET Compact Framework applications are the same
as the requirements to run Visual Studio .NET 2003. You need one of the following:
• Windows XP Professional
• Windows XP Home
One interesting caveat is that you won't be able to debug your applications in
the included emulator unless your computer is on a network with an active con-
nection. If you find yourself without a network, you'll need to install the Microsoft
LoopbackAdapter in order to fool the emulator into believing that you're on a
network. The following steps will get you up and running with the Loop back
Adapter.
2. Click Next until you get to the Is the hardware connected? screen. Select
Yes and then click Next.
3. Select Add a new hardware device from the Installed hardware list and
then click Next.
4. Select the Install the hardware that I manually select from a list
(Advanced) radio button and then click Next.
5. Select Network Adapters from the Common hardware types list and then
click Next.
3
Chapter 1
6. Select Microsoft from the Manufacturer list, select Microsoft Loop back
Adapter from the Network Adapter list, and then click Next.
7. Click Next to initiate the installation process and then click Finish.
Windows 2000
If you have a Windows 2000 system, follow these steps to install the Microsoft
Loop back Adapter:
2. Click Next until you get to the Choose a Hardware Task screen. Select Add/
Troubleshoot a device and then click Next.
3. Select Add a new device from the Devices list and then click Next.
4. Select the No, I want to select the hardware from a list radio button and
then click Next.
5. Select Network adapters from the Hardware types list and then click Next.
6. Select Microsoft from the Manufacturers list, select Microsoft Loop back
Adapter from the Network Adapter list, and then click Next.
7. Click Next to initiate the installation process and then click Finish.
Deployment
Your .NET Compact Framework applications can be targeted at a number of dif-
ferent devices:
• Pocket PC 2000
• Pocket PC 2002
• Windows CE 4.x
4
Getting Started
Installation
Based on my experience over the years working with the eMbedded Visual Tools
and now the Smart Device Extensions in Visual Studio .NET 2003, it's important to
have ActiveSync installed and working on a machine before installing the devel-
opment environment. Don't ask me why, it's just a chicken-and-egg thing. I've
tried it the other way around, and the result was that I had to reinstall Visual Studio
in order to get anything to work. Microsoft Knowledge Base article 813579
describes the inability to deploy a Smart Device Application once ActiveSync is
uninstalled and then reinstalled. In fact, our esteemed technical editor validated
just this situation the hard way and lost a day of editing in the process. Therefore,
I'm going to walk you through the ActiveSync Setup Wizard to ensure that you get
it installed properly. To get the latest and greatest version of ActiveSync, surf on
over to the Pocket PC downloads page at http: I /www. microsoft. com/mobile/
pocketpc/ downloads/. As of the writing of this book, the latest version is 3. 7.
Double-clicking msasync.exe will get things installed and shouldn't require a
reboot.
5
Chapter 1
Get Connected
Once ActiveSync is installed, it's time to get your device connected. Plug the USB
cable that came with your Pocket PC into your computer's USB port as well as the
Pocket PC itself. Most likely, you should hear a musical chime from both your Pocket
PC and your desktop computer when the two connect. Once the connection is
made, you'll be prompted to create a new partnership as shown in Figure 1-1.
r. Standard partnership
I want to synchronize data between my device and
this computer, keeping data such as e-mail and
calendar items up-to-date in both places.
i Guest partnership
I want to only copy and move information between my
device and this computer, or add and remove
programs. I do not want to synchronize data.
Creating a Partnership
As you can see in Figure 1-1, you need to choose between setting up a Standard or
Guest partnership. A Standard partnership allows you to move data between the
desktop and device, debug with Visual Studio .NET, and synchronize items such as
Outlook calendars, Pocket Access databases, and e-mail. This is the most widely
used type of partnership, and it creates a permanent relationship between your
computer and your device. On the other hand, a Guest partnership is more of a
transient type of relationship. An example would be where many different devices
need to connect to a single computer. A Guest partnership allows you to debug
with Visual Studio .NET and move data back and forth between the desktop and
device, but it doesn't allow any kind of synching.
6
Getting Started
Data Synchronization
It used to be that the only thing you had to worry about synching with was your
desktop computer. Now you have some other options to concern yourself with. As
shown in Figure 1-2, you can choose to synchronize either with your desktop com-
puter and/ or with the Microsoft Mobile Information Server. Very shortly, the
technology found in the Mobile Information Server will be merged into Microsoft
Exchange 2003 to give you even more choices when synchronizing your data.
You can synchronize data, such as e·mail messages and calendar items, between your
device and this desktop computer. However, if you have access to a Microsoft Mobile
Information Server with Microsoft Server ActiveSync, you can also choose some information
types to synchronize directly with a server, getting the most up·to·date information, even when
your desktop computer is turned off.
r Synchronize with Microsoft Mobile Information Server and/or this desktop computer
(Note: You must have access to a Microsoft Mobile Information Server with Server
ActiveSync to synchronize with a server. You will also need to have the necessary
information to configure your connection with the server.)
7
Chapter 1
Your device can have up to two partnerships or a partnership w~h only this computer. Do
you want your device to have a partne~ship and synchronize with only this computer?
R~move any e~isting partnerships on my device and set up a new partnership with just
thrs computer.
Synchronization Settings
Now that you've decided on one or two partnerships, you need to choose which
programs you want to synchronize with between your Pocket PC and your desktop
computer as shown in Figure 1-4. These choices are completely up to you and will
have no impact on your ability to debug and deploy .NET Compact Framework
applications from Visual Studio .NET. Alas, we've moved on from Pocket Access, so
you won't have to select it this time around.
With your synchronization setting decided upon, the creation of your
ActiveSync partnership is now complete, and the ActiveSync setup is finished. The
ActiveSync software now serves as the primary conduit between your Pocket PC
and your desktop computer. In addition to USB, ActiveSync can also communicate
with your Pocket PC via serial cable, infrared, Ethernet, and wireless 802.llx. Some
notable features found in ActiveSync include the following:
• A File Explorer that allows you to drag and drop files between your desktop
computer and your Pocket PC
8
Getting Started
• The ability to add and remove Pocket PC programs in the same manner as
Windows on the desktop
Mobile Device
0 . .A.vantGo ,A:.,-antGo Channels
~~Calendar Microsoft Outlook
~~ Contacts Microsoft Outlook
~ *
Favorites Internet Explorer
D @ Files Synchronized Files
~ ~ l nbox Microsoft 0 utlook
D ~Notes
_....., Microsoft 0 utlook
l:J
To find out more about and to customize what gets synchronized, click
on that information type in the list and then click Settings.
Settings.. I
9
Chapter 1
New Project button on the Start Page. Alternatively, you can go to the File menu,
and select New I Project to achieve the same result. Either way, you'll be presented
with the New Project dialog box as shown in Figure 1-5. In the Project Types pane,
you can choose which language you'd like to use. In the Templates pane, you get to
select a particular project template based on whether you want to build a Windows
or Web application among other things. In this case, you're going to choose a
Visual Basic Project and a Smart Device Application, specify a clever name for your
project, and then click OK.
29
I9'Q ::::I
Project Types: Templates: p~g ..::::.J
Name: ISmartDeviceApplicationl
Location: JC:\Documents and Settings\rtiffany\My Documents\Vis• :::J Browse ...
~ Mor~ OK
10
Getting Started
II
Welcome to the Smart Device Application Wizard
This wizard creates a project to develop an application to run on a smart device.
Class Library
Non·<;~raphical Application
Empty Project
The four project types listed in Table 1-1 are available to the Pocket PC 2000
and Pocket PC 2002.
ll
Chapter 1
Likewise, Table 1-2 describes the four project types that are available for
Windows CE .NET.
Despite the fact that you get all these great choices, I want you to select a
Pocket PC Windows Application and then click OK. Mter your computer thinks for
a moment, you'll be presented with your Pocket PC Windows project as shown in
Figure 1-7. It's time to start dragging, dropping, referencing, and coding.
.,c "
6 -F<2002 ........ (00fd) -
1
~~~-·-
~- lliL X Sttd P'"9" Forml.vb(OcJign) J
I ;:::::-::::- :::·.:: :.
:·::::::::::·:::·.::: : ......
p-.,_,
loll .... _
CO'ft~ton
D•...,
(;JOotoGm
!Jju.tfiO):
II""""""' . .. .... ' ..
........
=~~lbM$w ...... - ................
... . . . ... . . ' .
" ....... .
' . ' .. . .' . ' . .
f:}:ltwn.w
··-
'
o-
~
RJ.._._
-.,---;;,;- J. a,.,.._,,
........
~~ . g~~r~------------------------~~--~----~~~~---=-----J
P-r~i·:~::::::::::::~~~==:::::::::r::::::::=:======·=x~
~d -
-
~~ I loc«m
ltl ••"'''" 'eJ"""' 1ll...,,..._.,r1---------------------------------- ·llli'~- ... lo.,.,._..,, ·
Figure 1-7. Smart Device Project running inside Visual Studio .NET
12
Getting Started
Forms Designer
As you can see, your Pocket PC project looks just like a standard Windows Forms
project that you'd expect to see on the desktop. The only difference is that your
form is only 295 pixels high by 246 pixels wide. On the left side of the IDE, you can
see the familiar Toolbox containing almost 30 different controls to help you build
rich graphical user interfaces. These controls can be added to your form either by
double-clicking the control or by clicking and drawing the control on your form's
surface. Controls with a runtime user interface include the following:
• Button
• CheckBox
• ComboBox
• DataGrid
• DomainUpDown
• HscrollBar
• Label
• ListBox
• ListView
• NumericUpDown
• Panel
• PictureBox
• ProgressBar
• RadioButton
• StatusBar
• TabControl
• TextBox
13
Chapter 1
• ToolBar
• TrackBar
• TreeView
• VscrollBar
You also have a number of controls without any kind of runtime or design-
time user interface. Instead, these controls display themselves in the panel below
your form:
• ContextMenu
• ImageList
• InputPanel
• MainMenu
• OpenFileDialog
• SaveFileDialog
• Timer
Thinking back in time, I don't recall either Visual Basic 3 or 4 having this
many controls. Since the purpose of this walkthrough is to get you up and
running with the Smart Device Extensions, go ahead and drop a Button control
anywhere on the form you like. Normally, you might be asked to display "Hello
World" when you click on the button. Since this book targets SQL Server CE specif-
ically, I'll have you do things a little differently. Double-click the Button control to
bring up the code window for the button's click event. Inside that click event, type
MessageBox.Show("Hello SQL") as shown in Figure 1-8.
14
Getting Started
~~ -
•I I•
~])J .j ... l ~ < .. lilJ rn ... l
Pr~ f)()
''"'""·"" " ' - ::J
E.Jt~
e:::;: c~---:=
Cl.8tclmToal
s ~ .
ftiNIIM ~- l ...tl
1'\t~ C\Doc..,_....t..r.:IS.
~~ ~ ·
.,.
~- ·- - _·---- --· =- ·- 4 X
- o ...-.... 1
Before you move on, I have one little adjustment I'd like you to make while
you're working with the Forms Designer. One of my personal pet peeves deals with
the familiar circle with an X or OK in the middle that you find in the upper-right
corner of your application. Presumably, you tap on this to close your application.
You might be surprised to know that this is actually a minimize button. Under
normal circumstances, when you tap on this button, your program disappears,
but it's actually still running in the background, taking up resources. This behavior
might be fine for some applications, but it's not a good idea when your application
has an open connection to a SQL Server CE database. Luckily, there is a way to fix
this problem. With your form displayed in the Forms Designer, go to the Minimi-
zeBox property and set it to False. Problem solved. Tapping on the X or OK will now
close your application and return its resources back to the operating system.
15
Chapter 1
References
On the right side of the IDE in the Solution Explorer, you've probably noticed a
folder labeled References. The items beneath the References folder signify that
special functionality has been added to your application. For instance, the fact
that you see System.XML beneath the References folder means that the ability to
work with XML has been added to your application. If you need to give your
program more capabilities, doing so is as easy as adding a new reference. Since
this book is about SQL Server CE, you'll find yourself needing to add additional ref-
erences to get the job done. Practice this task by right -clicking the References
folder and then selecting Add Reference. The Add Reference dialog box will pop
up, displaying a list of .NET components as shown in Figure 1-9 .
.NET IProjects J
Browse ...
Component Name 1 Version I Path
Microsoft. Visu.aiBasic 7.0.5000.0 C:\Program Files\Microsoft Vi .. . Select
Microsoft. WindowsCE.Forms 1.0.5000.0 C:\Program Files\Microsoft Vi .. .
mscorlib 1.0.5000.0 C:\Program Files\Microsoft Vi .. .
System 1.0.5000.0 C:\Program Files\Microsoft Vi .. .
System.Data 1.0.5000.0 C:\Program Files\Microsoft Vi .. .
System.Data. Common 1.0.5000.0 C: \Program Files\Microsoft Vi .. .
System.Data. SqiClient I .0.5000.0 C:\Program Files\Microsoft Vi .. .
System. Data. SqiServerCe I .0.5000.0 C:\Program Files\Microsoft Vi... -
System .Drawing 1.0.5000.0 C:\Program Files\Microsoft Vi ...
System.Net.IrDA 1.0.5000.0 C:\Program Files\Microsoft Vi. ..
System.SR I .0.5000.0 C: \Program Files\Microsoft Vi. . . '= 1
'iv<tP.m .WP.h . "i"rvirP.< 1.n.~nnn . n 1:\Prnnrnm FiiP.<IMirrn<nft Vi... ..!.I
Icom.,.~
Sele(:ted Components:
I Source
"'••
OK Cancel Help
16
Getting Started
Project Properties
As you might imagine, your Smart Device Extension applications have all kinds of
properties that can be set through the Project Property Pages dialog box. This
dialog box can be activated by clicking the Project menu and then selecting the
<Application Name> Properties menu item. As shown in Figure 1-10, you can set
properties to optimize your application, alter the assembly name, and modify how
the compiler performs type conversions.
Inform..tlon
OK Cancel Help
For this walkthrough, I'm only interested in showing you how to control where
your application is deployed and how to give it an icon. If you click Device under
Common Properties, you'll see a textbox called Output file folder. This is the key to
making sure your application ends up where you intend it to go. If you want your
application to show up on the Start Menu, type\ Windows\Start Menu into the
17
Chapter 1
textbox. If, on the other hand, you want it to show up with all the other programs
like Pocket Word and Excel, type in \Windows \Start Menu \Programs. With your
output path set the way you want it, click Build under Common Properties in
Visual Basic .NET or General in C# to display the Application Icon combo box.
Click the ellipsis button to the right of the combo box in order to browse for an
icon. The icons included with Visual Studio .NET can be found at C: \Program
Files\MicrosoftVisual Studio .NET 2003\Common7\Graphics\icons. Once you've
chosen an icon, you'll see that its filename has been added to the Solution Explorer
if you're using Visual Basic .NET. In order to prevent the icon from being sent along
as just an additional file, you need to highlight the filename, drop down to the
Properties area below the Solution Explorer, and set the Build Action property to
Embedded Resource. InC#, you won't see the icon in the Solution Explorer.
18
Getting Started
LetJs Run It
The wait is now over. If you've followed my instructions carefully, then your new
.NET Compact Framework application is ready to go. Unfortunately, there are just
a few more steps to follow. First of all, you need to tell Visual Studio .NET where to
deploy your application when you run it. This is accomplished by going to the
Deployment Device combo box on the toolbar and selecting either Pocket PC
Device as shown in Figure 1-11 or Pocket PC 2002 Emulator as shown in
Figure 1-12. Remember, your device must be connected to your desktop via
ActiveSync in order to successfully deploy your application to your device.
Pocket PC Device
=====
· I P. ~
Figure 1-11. Deploying to a Pocket PC device
t:!l
Pocket PC 2002 Emulator (Default) ru •
One other choice you can make before running your program is to select
either Debug or Release from the Solution Configurations combo box found on the
toolbar. If you choose Debug, you'll be able to set breakpoints and utilize the full
debugging capabilities ofVisual Studio .NET regardless of whether you're
deploying to the emulator or to your Pocket PC. If you choose Release, Visual
Studio .NET will build an optimized executable for deployment. For our purposes,
select Pocket PC 2002 Emulator and Debug, and then click the Start button on the
toolbar as shown in Figure 1-13 in order to get things going.
A Deploy dialog box will pop up immediately after clicking the Start button, as
shown in Figure 1-14. This dialog box is somewhat redundant to the choices you've
already made, but it gives you a second chance to change your mind in regards to
your deployment target. It also reminds you that if your device doesn't already
have the .NET Compact Framework installed, it will take care of that task for you
automatically.
19
Exploring the Variety of Random
Documents with Different Content
The sides of this (Fig, 101, a, a), facing east and west are three
and a half feet long, two feet high on the south end, and two and a
half feet on the north. They are in one piece, which is secured by
nailing the boards which form them to cleats, which are one inch
from the ends. The north end (Fig, 101, b) is three feet by two and a
half feet, the south (Fig. 101, b), three feet by two, and made the
same as are the sides. The slanting top of the sides (Fig. 101, a, a)
is made by using for the upper board, the strip formed by sawing
diagonally from corner to corner a board six inches wide and three
feet long. The cover (Fig. 101, g), which is removed in the figure, is
large enough to cover the top and project one inch at both ends. It
should be battened, and held in one piece by cleats (Fig. 101, h) four
inches wide, nailed on to the ends. These will drop over the ends of
the box, and thus hold the cover in place, and prevent rain and snow
from driving in. When in place this slanting cover permits the rain to
run off easily, and will dry quickly after a storm. By a single nail at
each corner the four sides may be tacked together about the hives,
when they can be packed in with straw (Fig. 101), which should be
carefully done if the day is cold, so as not to disquiet the bees. At the
centre and bottom of the east side (Fig. 101, c), cut out a square
eight inches each way, and between this and the hive place a
bottomless tube (the top of this tube is represented as removed in
figure to show entrance to hive), before putting around the straw and
adding the cover. This box should be put in place before the bleak
cold days of November, and retained in position till the stormy winds
of April are passed by. This permits the bees to fly when very warm
weather comes in winter or spring, and requires no attention from the
apiarist. By placing two or three hives close together in autumn—yet
never move the colonies more than three or four feet at any one
time, as such removals involve the loss of many bees—one box may
be made to cover all, and at less expense. Late in April these may
be removed and packed away, and the straw carried away, or
removed a short distance and burned.
CHAFF HIVES.
Messrs. Townley, Butler, Root, and others, prefer chaff hives,
which are simply double-walled hives, with the four or five inch
chambers filled with chaff. The objection to these I take to be: First,
Danger that so limited a space would not answer in severe seasons;
Second, That such cumbrous hives would be inconvenient to handle
in summer; and, Third, A matter of expense. That they would in part
supply the place of shade, is, perhaps, in their favor, while Mr. A. I.
Root thinks they are not expensive.
BURYING BEES.
Another way to winter safely and very economically, is to bury the
bees. If this is practiced the ground should either be sandy or well
drained. If we can choose a side-hill it should be done. Beneath the
hives and around them, straw should be placed. I should advise
leaving the entrance well open, yet secure against mice. The hives
should all be placed beneath the surface level of the earth, then form
a mound above them sufficient to preserve against extreme warmth
or cold. A trench about the mound to carry the water off quickly is
desirable. In this arrangement the ground acts as a moderator. Five
colonies thus treated the past winter, (1877-8) lost all told less than
one-half gill of bees. As this method has not been so long tried, as
the others, I would suggest caution. Try it with a few colonies, till you
are assured as to the best arrangement, and of its efficacy. I am
inclined to think that it is next to a good snow-bank, as a winter
repository.
SPRING DWINDLING.
As already suggested, this is not to be feared if we keep our bees
breeding till late autumn. It may be further prevented by forbidding
late autumn flights, frequent flights in winter, when the weather is
warm, and too early flying in spring. These may all be curtailed or
prevented by the packing system as described above, as thus
prepared the bees will not feel the warmth, and so will remain quiet
in the hive. Nine colonies which I have packed have been
remarkably quiet, and are in excellent condition this, February 25th,
while two others unpacked have flown day after day, much, I fear, to
their injury. I would leave bees in the packing till near May, and in the
cellar or ground, till early flowers bloom, that we may secure against
too rapid demise of bees in spring.
CHAPTER XVIII.
THE HOUSE APIARY.
DESCRIPTION.
This is a double-walled house, which may be rectangular or
octagonal in form. The outer wall should be of brick, and made as
thin as possible. Inside of this there should be wooden strips two-
inches thick, which should receive a layer of paper-sheeting inside,
which may be held by nailing strips two-inches wide immediately
inside the first mentioned strips. These last strips should receive lath,
after which all should be plastered. This may cost more than a purely
wooden structure, but it will be more nearly frost-proof than any other
kind of wall, and in the end will be the cheapest. There will be two
dead air-chambers, each two inches deep, one between the paper
and brick, the other between the paper and the plaster. The entire
wall will be at least eight inches thick. If desired, it may be made less
thick by using one-inch strips, though for our very severe winters the
above is none too thick. The doors and windows should be double
and should all shut closely against rubber. The outer ones should
consist of glass, and should be so hung as to swing out, and in hot
weather should be replaced with door, and window-screens, of
coarse, painted, wire gauze. A small window just above each colony
of bees is quite desirable.
Somewhere in the walls there should be a ventilating tube—a
brick flue would be very good—which should open into the room just
above the floor. Above it might open into the attic, which should be
well aired. Ventilators such as are so common on barns might be
used.
The pipe for admitting air, should, as in the cellar before
described, pass through the ground and enter the floor from below. A
good cellar, well ventilated and thoroughly dry will be convenient,
and should not be neglected. I would have the building but one story,
with joists in ceiling above eight inches thick. Above these I would
sheet with building paper, fastened by nailing strips two inches deep
on top, above which I would ceil with matched boards. I should lath
and plaster below the joists. The hives, which are to be kept
constantly in this house, may rest on two rows of shelves, one at the
floor, the other three feet high, and should be arranged for both top
and side storing in the small section frames. Indeed, the hive need
only consist of the two rabbeted side-boards (Fig, 30, c), and a
division-board with quilt. The entrances of course pass through the
wall. An alighting-board, so hinged as to be let down in summer, but
tightly closed over the entrance during very severe winter weather, I
should think would be very desirable. Between the double windows,
which it will be remembered shut closely against rubber, sacks of
chaff may be placed in winter, if found necessary to keep the proper
temperature. With few colonies this might be very necessary. The
adjacent entrances should vary in color, so that young queens would
not go astray, when they returned from their "Marriage flight."
There are various dangers that are likely to vex the apiarist, and
even to stand in the way of successful apiculture.—Yet, with
knowledge, most, if not all of these evils may be wholly vanquished.
Among these are: Robbing among the bees, disease, and
depredations from other animals.
ROBBING.
This is a trouble that often very greatly annoys the inexperienced.
Bees only rob at such times as the general scarcity of nectar forbids
honest gains. When the question comes: Famine or theft, like many
another, they are not slow to choose the latter. It is often induced by
working with the bees at such times, especially if honey is scattered
about or left lying around the apiary. It is especially to be feared in
spring, when colonies are apt to be weak in both honey and bees,
and thus are unable to protect their own meager stores. The
remedies for this evil are not far to seek:
First. Strong colonies are very rarely molested, and are almost
sure to defend themselves against marauders; hence, it is only the
weaklings of the apiarist's flock that are in danger. Therefore, regard
for our motto, "Keep all colonies strong," will secure against harm
from this cause.
Second. Italians, as before stated, are fully able, and quite as
ready, to protect their rights against neighboring tramps. Woe be to
the thieving bee that dares to violate the sacred rights of the home of
our beautiful Italians. For such temerity is almost sure to cost the
intruder its life.
But weak colonies, like our nuclei, and those too of black bees,
are still easily kept from harm. Usually, the closing of the entrance so
that but a single bee can pass through, is all sufficient. With the hive
we have recommended, this is easily accomplished by simply
moving the hive back.
Another way to secure such colonies against robbing is to move
them into the cellar for a few days. This is a further advantage, as
less food is eaten, and the strength of the individual bees is
conserved by the quiet, and as there is no nectar in the fields no loss
is suffered.
In all the work of the apiary at times of no honey gathering, we
cannot be too careful to keep all honey from the bees unless placed
in the hives. The hives, too, should not be kept open long at a time.
Neat, quick work should be the watch-word. During times when
robbers are essaying to practice their nefarious designs, the bees
are likely to be more than usually irritable, and likely to resent
intrusion; hence the importance of more than usual caution, if it is
desired to introduce a queen.
DISEASE.
The common dysentery—indicated by the bees soiling their
hives, as they void their feces within instead of without—which has
been so free, of late, to work havoc in our apiaries, is, without doubt,
I think, consequent upon wrong management on the part of the
apiarist, as already suggested in Chapter XVII. As the methods to
prevent this have already been sufficiently considered, we pass to
the terrible
FOUL BROOD.
This disease, said to have been known to Aristotle—though this
is doubtful, as a stench attends common dysentery—though it has
occurred in our State as well as in States about us, is not familiar to
me, I having never seen but one case, and that on Kelly's Island, in
the summer of 1875, where I found it had reduced the colonies on
that Island to two. No bee malady can compare with this in
malignancy. By it Dzierzon once lost his whole apiary of 500
colonies.—Mr. E. Rood, first President of the Michigan Association,
has lost his bees two or three times by this same terrible plague.
The symptoms are as follows: Decline in the prosperity of the
colony, because of failure to rear brood. The brood seems to putrefy,
becomes "brown and salvy," and gives off a stench, which is by no
means agreeable, while later, the caps are concave instead of
convex, and have a little hole through them.
There is no longer any doubt as to the cause of this fearful
plague. Like the fell "Pebrine," which came so near exterminating the
"silk worm," and a most lucrative and extensive industry in Europe, it,
as conclusively shown by Drs. Preusz and Shönfeld, of Germany, is
the result of fungous or vegetable growth. Shönfeld not only infected
healthy bee larvæ, but those of other insects, both by means of the
putrescent foul brood, and by taking the spores.
Fungoid growths are very minute, and the spores are so
infinitesimally small as often to elude the sharp detection of the
expert microscopist. Most of the terrible, contagious diseases that
human flesh is heir to, like typhus, diphtheria, cholera, small pox,
&c., &c., are now thought to be due to microscopic germs, and
hence to be spread from home to home, and from hamlet to hamlet,
it is only necessary that the spores, the minute seeds, either by
contact or by some sustaining air current, be brought to new soil of
flesh blood or other tissue—their garden spot—when they at once
spring into growth, and thus lick up the very vitality of their victims.
The huge mushroom will grow in a night. So too, these other plants
—the disease germs—will develop with marvelous rapidity; and
hence the horrors of yellow fever, scarlatina, and cholera.
To cure such diseases, the fungi must be killed. To prevent their
spread, the spores must be destroyed, or else confined. But as these
are so small, so light, and so invisible—easily borne and wafted by
the slightest zephyr of summer, this is often a matter of the utmost
difficulty.
In "Foul Brood" these germs feed on the larvæ of the bees, and
thus convert life and vigor into death and decay. If we can kill this
miniature forest of the hive, and destroy the spores, we shall
extirpate the terrible plague.
REMEDIES.
If we can find a substance that will prove fatal to the fungi, and
yet not injure the bees, the problem is solved. Our German scientists
—those masters in scientific research and discovery, have found this
valuable fungicide in salicylic acid, an extract from the same willows
that give us pollen and nectar. This cheap white powder is easily
soluble in alcohol, and when mixed with borax in water.
Mr. Hilbert, one of the most thoughtful of German bee-keepers,
was the first to effect a radical cure of foul brood in his apiary by the
use of this substance. He dissolved fifty grains of the acid in five
hundred grains of pure spirits. One drop of this in a grain of distilled
water is the mixture he applied. Mr. C. F. Muth, from whom the above
facts as to Herr Hilbert are gathered, suggests a variation in the
mixture.
Mr. Muth suggests an improvement, which takes advantage of
the fact that the acid, which alone is very insoluble in water, is, when
mixed with borax, soluble. His recipe is as follows: One hundred and
twenty-eight grains of salicylic acid, one hundred and twenty-eight
grains of soda borax, and sixteen ounces distilled water. There is no
reason why water without distillation should not do as well.
This remedy is applied as follows: First uncap all the brood, then
throw the fluid over the comb in a fine spray. This will not injure the
bees, but will prove fatal to the fungi.
If the bees are removed to an empty hive, and given no comb for
three or four days, till they have digested all the honey in their
stomachs, and then prevented visiting the affected hive, they are
said to be out of danger. It would seem that the spores are in the
honey, and by taking that, the contagion is administered to the young
bees. The honey may be purified from these noxious germs, by
subjecting it to the boiling temperature, which is generally, if not
always, fatal to the spores of fungoid life. By immersing the combs in
a salicylic acid solution, or sprinkling them with the same, they would
be rendered sterile, and could be used without much fear of
spreading contagion. The disease is probably spread by robber bees
visiting affected hives, and carrying with them in the honey the fatal
germs.
I have found that a paste made of gum tragacanth and water is
very superior, and I much prefer it for either general or special use to
gum Arabic. Yet it soon sours—which means that it is nourishing
these fungoid plants—and thus becomes disagreeable. I have found
that a very little salicylic acid will render it sterile, and thus preserve it
indefinitely.
ENEMIES OF BEES.
Swift was no mean entomologist, as shown in the following
stanza:
The eggs of the bee moth are white, globular and very small.
These are usually pushed into crevices by the female moth as she
extrudes them, which she can easily do by aid of her spy-glass-like
ovipositor. They may be laid in the hive, in the crevice underneath it
or about the entrance.—Soon these eggs hatch, when the gray, dirty
looking caterpillars, with brown heads, seek the comb on which they
feed. To better protect themselves from the bees, they wrap
themselves in a silken tube (Fig, 102) which they have power to spin.
They remain in this tunnel of silk during all their growth, enlarging it
as they eat. By looking closely, the presence of these larvæ may be
known by this robe of glistening silk, as it extends in branching
outlines (Fig, 103) along the surface of the comb. A more speedy
detection, even, than the defaced comb, comes from the particles of
comb, intermingled with the powder-like droppings of the caterpillars,
which will always be seen on the bottom-board in case the moth-
larvæ are at work. Soon, in three or four weeks, the larvæ are full
grown (Fig, 104). Now the six jointed, and the ten prop-legs—making
sixteen in all, the usual number of caterpillars—are plainly visible.
Fig. 106.
These larvæ are about an inch long, and show, by their plump
appearance, that they at least, can digest comb. They now spin their
cocoons, either in some crevice about the hive, or, if very numerous,
singly (Fig, 105, a) or in clusters (Fig, 105, b) on the comb, or even
in the drone-cells (Fig, 105, c) in which they become pupæ, and in
two weeks, even less, sometimes, during the extreme heat of
summer, the moths again appear. In winter, they may remain as
pupæ for months. The moths or millers—sometimes incorrectly
called moth-millers—are of an obscure gray color, and thus so mimic
old boards, that they are very readily passed unobserved by the
apiarist. They are about three-fourths of an inch long, and expand
(Fig, 106) nearly one and one-fourth inches. The females (Fig, 107)
are darker than the males (Fig, 107), possess a longer snout, and
are usually a little larger. The wings, when the moths are quiet (Fig,
107) are flat on the back for a narrow space, then slope very
abruptly. They rest by day, yet, when disturbed, will dart forth with
great swiftness, so Réaumur styled them "nimble-footed." They are
active by night, when they essay to enter the hive and deposit their
one or two hundred eggs. If the females are held in the hand they
will often extrude their eggs; in fact, they have been known to do this
even after the head and thorax were severed from the abdomen, and
still more strange, while the latter was being dissected.
Fig. 107.
Male. Female.
HISTORY.
REMEDIES.
In Europe, late writers give very little space to this moth. Once a
serious pest, it has now ceased to alarm, or even disquiet the
intelligent apiarist. In fact, we may almost call it a blessed evil, as it
will destroy the bees of the heedless, and thus prevent injury to the
markets by their unsalable honey, while to the attentive bee-keeper it
will work no injury at all. Neglect and ignorance are the moth
breeders.
As already stated, Italian bees are rarely injured by moths, and
strong colonies never. As the enterprising apiarist will only possess
these, it is clear that he is free from danger. The intelligent apiarist
will also provide, not only against weak, but queenless colonies as
well, which from their abject discouragement, are the surest victims
to moth invasion. Knowing that destruction is sure, they seem, if not
to court death, to make no effort to delay it.
In working with bees, an occasional web will be seen glistening in
the comb, which should be picked out with a knife till the
manufacturer—the ruthless larva—is found, when it should be
crushed. Any larva seen about the bottom board, seeking a place to
spin its cocoon, or any pupæ, either on comb or in crack, should also
be killed. If, through carelessness, a colony has become hopelessly
victimized by these filthy, stinking, wax devourers, then the bees and
any combs not attacked should be transferred to another hive, after
which the old hive should be sulphured by use of the smoker, as
before described (page 216), then by giving one or two each of the
remaining combs to strong colonies, after killing any pupæ that may
be on them, they will be cleaned and used, while by giving the
enfeebled colony brood, if it has any vigor remaining, and if
necessary a good queen, it will soon be rejoicing in strength and
prosperity.
We have already spoken of caution as to comb honey and
frames of comb (page 216), and so need not speak further of them.
Fig. 109.
Larva.
Imago.
This louse (Fig, 109) is a wingless Dipteron, and one of the
uniques among insects. It is a blind, spider-like parasite, and serves
as a very good connecting link between insects and spiders, or, still
better, between the Diptera, where it belongs, and the Hemiptera,
which contains the bugs and most of the lice. It assumes the semi-
pupa state almost as soon as hatched, and strangest of all, is,
considering the size of the bee on which it lives, and from which it
sucks its nourishment, enormously large. Two or three, and
sometimes even more, (the new Encyclopedia Britannica says 50 or