Wednesday, April 7, 2010

Visual Basic - Synchronize Client Computer Date/Time From a SQL Server

The code below is used to synchronize the client computer from MS SQL Server, sometimes the users  may change their computer local time in-order to trick the system that he/she encoded the data entry on time. Oh, if you're the database administrator or programmer it's a very headache how to figure it out, why it is happen this way. Sample scenario, accounts receivable should be encoded prior to cut-off period, then user name "Michelle" forgot to encode the data, a day after cut-off period she realize encode the accounts receivable data, she might change the local time in-order to encode in previous dates. Basically, visual basic program compares the entry date (date picker component) and the system/local time, if she change the system date less than current date, you might wonder why the data not posted in ledger to think that all entries are encoded on timely basis. So, how to prevent it. Use the code below and don't forget to create a stored procedure called "Get_Server_Date". Call this function as many as you can for example during Loan Event, Add New Entry, Edit Entry, Save Entry, Delete Entry. Anyway it's very fast, the user can't recognize that you're synchronizing from the server time.
Note: I assume the all your data tables has these two or three fields
User_Name - the one who transact the data
DateEncoded/Modified  - the transaction date base on user's local time.
Computer Name - Optional, it use to trace the users location.
If it's not added to your data table, please do apply the fields it may help you trace your transactions.

'------ VB Code ----------
'Declaration
Dim Const mCon="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Mydatabase;Data Source=MyComputerName\SQLEXPRESS"



'Note : Change the Mydatabase to your Database Name
 '            MyComputerNmae = Your Database Server Name





Private Sub Form_Load()




       Call SynChronize_Date_Server()

End Sub



Function SynChronize_Date_Server()
On Error Resume Next
    Dim tmp1 As Date
    With Main.ado1   ' Add adodc1 object to the form and name it ado1
        .ConnectionString = mCon
        .CommandType = adCmdStoredProc
        .RecordSource = "sp_getserverdate;1"
        .Refresh
        Date = Format(.Recordset!ServerDate, "mm/dd/yy")
        Time = Format(.Recordset!ServerDate, "hh:mm:ss")
    End With
End Function

Function Get_Server_Date() As Date

On Error Resume Next
    Dim tmp1 As Date
    With Main.ado1
        .ConnectionString = mCon
        .CommandType = adCmdStoredProc
        .RecordSource = "sp_getserverdate;1"
        .Refresh
        Get_Server_Date = Format(.Recordset!ServerDate, "mm/dd/yy")
    End With
End Function
'-------------------------------- STORED PROCEDURED CODE ----------------------------


USE [Inventry]
GO
/****** Object:  StoredProcedure [dbo].[sp_getserverdate]    

Script Date: 04/20/2010 01:19:56 ******/

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER  proc [dbo].[sp_getserverdate]
as
set nocount on
select getdate() as ServerDate




















10 comments:

sap upgrades said...

This post gives you method to synchronize date/time from a SQL server. The method is easy to implement. You can get the output with a simple query. This information is very useful. I like your work. Thanks for the post.

html5 player said...

Interesting post. Keep posting such kind of information on your blog. I bookmarked it for continuous visit.

Buy Contact Lenses said...

I don’t skills need to I offer you with thanks! i am altogether appalled by your article. You saved my time. Thanks 1,000,000 for sharing this text.

periyannan said...

Interesting stuff to read and useful to improve knowledge.
Keep posting.
Biotech Internships | internships for cse students | web designing course in chennai | it internships | electrical engineering internships | internship for bcom students | python training in chennai | web development internship | internship for bba students | internship for 1st year engineering students

InfinityBender42 said...

manisa
sakarya
sivas
van
elazığ
DD4P3

KızılYıldızlıKız66 said...

https://titandijital.com.tr/
balıkesir parça eşya taşıma
eskişehir parça eşya taşıma
ardahan parça eşya taşıma
muş parça eşya taşıma
RE7D

ElectricVoyageress1Q23 said...

kocaeli evden eve nakliyat
kilis evden eve nakliyat
bursa evden eve nakliyat
trabzon evden eve nakliyat
hakkari evden eve nakliyat
XYBVC

7D061Lilith21B10 said...

76DDA
Malatya Parça Eşya Taşıma
Kırşehir Lojistik
İzmir Evden Eve Nakliyat
Edirne Parça Eşya Taşıma
Niğde Evden Eve Nakliyat

DCBC8Saanvi2F74E said...

6C879
sakarya sesli sohbet siteleri
sesli sohbet siteleri
karabük kadınlarla rastgele sohbet
kırıkkale canlı sohbet ücretsiz
canlı sohbet siteleri ücretsiz
bolu canlı sohbet uygulamaları
adıyaman canlı sohbet odası
kadınlarla görüntülü sohbet
kütahya görüntülü sohbet kızlarla

KP EDUCATIONAL NEWS said...

A very awesome blog post. We are really grateful for your blog post.
Akurdupoetry

Post a Comment

 
Powered by Blogger