Sign in
Smart Client Data
This blog describes some of the Data features specific to Smart Clients. This includes Windows Forms, Devices and Visual Studio Tools for Office. The Smart Client Data team, AKA VB Data, is responsible for features such as the Data Sources Window, Typed
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
Atom
RSS for comments
Search
Tags
Blogicles
Occasionally Connected Data
Post Whidbey Thinking
Presentations
Whidbey Q & A
Archive
Archives
August 2006
(1)
April 2006
(2)
February 2006
(3)
November 2005
(5)
October 2005
(3)
September 2005
(2)
August 2005
(6)
July 2005
(4)
June 2005
(6)
Building SQL manually considered harmful
MSDN Blogs
>
Smart Client Data
>
Building SQL manually considered harmful
Building SQL manually considered harmful
SmartClientData
22 Nov 2005 2:29 PM
Comments
3
I just got done fixing a painful bug. The long and short of it is that I had code like this (simplified a lot for brevity):
Public Sub StoreSyncDate() Dim sql As String = "insert into SyncTimes (ObjectID, SyncDate) values ({0}, '{1}')" sql = String.Format(sql, Me.ID, DateTime.Now) Me.Executequery(sql) End Sub
On my machine, sql gets passed as a string like
"insert into SyncTimes (ObjectID, SyncDate) values (42, '11/22/2005 11:34:45 AM')"
. Life is good (ignore the SQL injection security problem for the moment).
Then a co-worker in Ireland emails me to ask why my application has broken. Things were working fine earlier in the month, but now he's getting an unhandled exception. What's going on here? Head over to your Regional settings in the Control Panel and change your region to English (Ireland) for some local flavor:
"insert into SyncTimes (ObjectID, SyncDate) values (42,
'22/11/2005 11:34:15'
)"
. There's no month 22, SQL complains, life is not good. The even trickier part is before the 13th of the month, dd/mm/yyyy strings turn in to valid mm/dd/yyyy strings. This is probably worse since it's subtle data corruption rather than an obvious error.
So the moral of the story is, be smarter than me. You never know what will go wrong when you're not using parameterized queries.
Ryan Cavanaugh
3 Comments
Blog - Comment List MSDN TechNet
Comments
Loading...
Leave a Comment
Name
Comment
Please add 4 and 2 and type the answer here:
Post