I did exact same thing before, although not using CSLA. I
put my check into a class that was called from Sub Main(). If DB was too
new, software would display a message and fold (Application.Exit(), Exit Sub).
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Magenic ®
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: reagan123
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 9:08 AM
To: Sergey Barskiy
Subject: [CSLA .NET] OT: Database Version Check
Hello everyone,
Quick question... Currently, out database has a table in it called
"DatabaseVersion". This table just holds a version number that
we change as the database changes (I.E.- 1.0.0.2).
Basically, I need the software to check this value to make sure the version of
the software they are running is compliant with the version of the database. (I
know it sounds like this shouldn't happen, but it does in our situation)
If it were you, where in your code would you put a check like this?
Anyone do anything similar? Any tips or ideas would be greatly
appreciated.
Thanks!
Sergey,
I think that the question is more like, since all of the DB communication
goes through Csla Business layer, what type of object would you use to
get the database version. If that was truly the question, then my answer
would be: use CommandObject, and place the Database version in a Result
property of it:
Usage being:
string dbVersion = DBVersionCommand.Execute();
and obviously server side implementation – data access
part goes to DBVersionCommand.DataPortalExecute()
Nermin
From: Sergey Barskiy
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 8:16 AM
To: Nermin Dibek
Subject: RE: [CSLA .NET] OT: Database Version Check
I did exact same thing before, although not using CSLA. I
put my check into a class that was called from Sub Main(). If DB was too
new, software would display a message and fold (Application.Exit(), Exit Sub).
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Magenic ®
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: reagan123
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 9:08 AM
To: Sergey Barskiy
Subject: [CSLA .NET] OT: Database Version Check
Hello everyone,
Quick question... Currently, out database has a table in it called
"DatabaseVersion". This table just holds a version number that
we change as the database changes (I.E.- 1.0.0.2).
Basically, I need the software to check this value to make sure the version of
the software they are running is compliant with the version of the database. (I
know it sounds like this shouldn't happen, but it does in our situation)
If it were you, where in your code would you put a check like this?
Anyone do anything similar? Any tips or ideas would be greatly
appreciated.
Thanks!
Yes you have an object inheriting from CommandBase, implement
DataPortal_Execute (db SP call that returns the ver. number), static Execute is
your FactoryMethod that returns the version number, on the client side (and
internally calls DataPortal.Execute<DBVersionCommand>(obj)), you will
have to have a Result field property to serialize the value back from DataPortal_Execute
to Execute(), and that is essentially it.
From: reagan123
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 8:57 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] RE: OT: Database Version Check
Wow...thanks everyone for the replies... sounds like I'm on
the right track.
Nermin, I was thinking command object would be the way to go. So
basically I have an object that inherits from command object and it's sole
responsibility is to get this value... does that seem right?
Thanks again for the responses :)
My bad. I totally agree.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Magenic ®
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: Nermin Dibek
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 9:42 AM
To: Sergey Barskiy
Subject: RE: [CSLA .NET] OT: Database Version Check
Sergey,
I think that the question is more like, since all of the DB
communication goes through Csla Business layer, what type of object would
you use to get the database version. If that was truly the question, then
my answer would be: use CommandObject, and place the Database version in
a Result property of it:
Usage being:
string dbVersion = DBVersionCommand.Execute();
and obviously server side implementation – data access
part goes to DBVersionCommand.DataPortalExecute()
Nermin
From: Sergey Barskiy [mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 8:16 AM
To: Nermin Dibek
Subject: RE: [CSLA .NET] OT: Database Version Check
I did exact same thing before, although not using CSLA. I
put my check into a class that was called from Sub Main(). If DB was too
new, software would display a message and fold (Application.Exit(), Exit Sub).
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Magenic ®
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: reagan123
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 9:08 AM
To: Sergey Barskiy
Subject: [CSLA .NET] OT: Database Version Check
Hello everyone,
Quick question... Currently, out database has a table in it called
"DatabaseVersion". This table just holds a version number that
we change as the database changes (I.E.- 1.0.0.2).
Basically, I need the software to check this value to make sure the version of
the software they are running is compliant with the version of the database. (I
know it sounds like this shouldn't happen, but it does in our situation)
If it were you, where in your code would you put a check like this?
Anyone do anything similar? Any tips or ideas would be greatly
appreciated.
Thanks!
nermin:...what type of object would you use to get the database version. If that was truly the question, then my answer would be: use CommandObject, and place the Database version in a Result property of it:
...
You might also find it handy as you do this to have more generalized commands that can invoke an arbitrary stored procedure and return the result, or fetch a specific scalar value given an arbitrary SQL statement.
More generalized, meaning outside of csla, right? I would
recommend against that approach. I find the CommandBase simple enough,
and more importantly one has to think about the value of Csla where code can be
easily ported to run on a separate physical servers. If you move your
code to a “more generalized commands” you loose that flexibility,
you can not port your code from running locally to a multi-layer solution
without having to change it.
Lets assume that your “generalized command” executes
on a DAL, that runs on Application server – how do you pass it to the
client, which lets say is a WinForm on another machine? Generalized solution
then has to assume only a single layer app, or it has to “invent” a
new object or a set of objects that communicate the result back to the client.
Or perhaps I am missing something here?
Nermin
From: rsbaker0
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 9:22 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] RE: OT: Database Version Check
nermin:
...what type of object would you use to get the database version. If that was truly the question, then my answer would be: use CommandObject, and place the Database version in a Result property of it:
...
You might also find it handy as you do this to have more generalized commands that can invoke an arbitrary stored procedure and return the result, or fetch a specific scalar value given an arbitrary SQL statement.
Looks good – only one thing: I would make constructor private.
That way the Factory method is the only way to get to the instance of the
Command object.
Nermin
From: reagan123
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 10:47 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] RE: RE: OT: Database Version Check
Okay... I think I have it working. Does the following
look correct. It's my first attempt at a commandbase type object.
<Serializable()> _
Public Class DatabaseVersionCommand
Inherits
Csla.CommandBase
Private
_databaseVersion As String
Public
ReadOnly Property DatabaseVersion() As String
Get
Return _databaseVersion
End Get
End
Property
Public
Sub New()
End Sub
Public
Shared Function Execute() As String
Dim cmd As New DatabaseVersionCommand
cmd = Csla.DataPortal.Execute(Of DatabaseVersionCommand)(cmd)
Return cmd.DatabaseVersion
End
Function
Protected Overrides Sub DataPortal_Execute()
Using cn As New SqlConnection(GetConnectionString)
cn.Open()
Using cm As SqlCommand = cn.CreateCommand
cm.CommandType = CommandType.Text
cm.CommandText = "SELECT DATABASE_VERSION FROM VERSION"
Dim version As String = TryCast(cm.ExecuteScalar, String)
_databaseVersion = version
End Using
End Using
End Sub
End Class
nermin:More generalized, meaning outside of csla, right? I would recommend against that approach. I find the CommandBase simple enough, and more importantly one has to think about the value of Csla where code can be easily ported to run on a separate physical servers.
No, it's still a CSLA CommandBase, just a more general one as opposed to one that just invokes a specific stored procedure.
For example, (just to illustrate), you could write a single CommandBase class to execute any parameterless stored procedure. Then you could implement a static Execute method on the class that just takes the procedure name. You can even make this generic so that the type of the result can be specified (e.g. you might be getting back a date, int, string, etc.). If you want some encapsulation, then you can wrap the invocation in a method or class (e.g. bool VersionChecker.CheckVersion())
I'm a big fan of leveraging CSLA to do as much as possible, so no I wasn't proposing a non-CSLA solution.
I actually do like that idea! Sorry for miss-interpreting your
thoughts in my original reply.
From: rsbaker0
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 11:37 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] RE: RE: OT: Database Version Check
nermin:
More generalized, meaning outside of csla, right? I would recommend against that approach. I find the CommandBase simple enough, and more importantly one has to think about the value of Csla where code can be easily ported to run on a separate physical servers.
No, it's still a CSLA CommandBase, just a more general one as opposed to one
that just invokes a specific stored procedure.
For example, (just to illustrate), you could write a single CommandBase
class to execute any parameterless stored procedure. Then you could implement a
static Execute method on the class that just takes the procedure name.
You can even make this generic so that the type of the result can be specified
(e.g. you might be getting back a date, int, string, etc.).
I'm a big fan of leveraging CSLA to do as much as possible, so no I wasn't
proposing a non-CSLA solution.
We do exactly this (and also provide upgrade capability if you have installed a handler to respond to the "database version wrong" event).
I agree that the plumbing can be daunting (chicken versus the egg problem generally), but in a nutshell our version checker is called immediately after a connection is established to database. If the version is wrong and an upgrade engine is installed, then there is an opportunity to upgrade, otherwise the version checker throws an exception.
We have CSLA bolted on an ORM (the Wilson ORMapper to be specific) so we do the check right after the ORM layer is initialized. The ORM might have mappings that aren't valid with the current database, though, so the version check and upgrade process have to be done with that in mind (e.g. you have to use either version-independent objects or direct SQL of some sort.)
I am currently working on a system where the aim is to have a business object where the 'fetch' returns version information and 'update' updates this version number as well as running all the required data definition commands. It is up to the user interface layer to use this object at start up.
Copyright (c) Marimer LLC