Solved

Using Delphi to get the MS SQL Server 2005 database timestamp

Posted on 2011-03-14
4
1,053 Views
Last Modified: 2012-05-11
I need to retrieve the database timestamp from an MS SQL Server 2005 database.  The Transact SQL method is "SELECT @@DBTS".

How can I do this using a Delphi component?  Do I use a TADOStoredProc? If so, what it the procedure name?

Thanks,

Eric
0
Comment
Question by:cerebrumconsulting
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 35133427
you can use adocommand, adoquery or adostoredprocedure
0
 

Author Comment

by:cerebrumconsulting
ID: 35133456
I tried the TADOQuery with "SELECT @@DBTS" but got no value back
0
 
LVL 26

Accepted Solution

by:
tigin44 earned 500 total points
ID: 35133478
use an alias for the field name and reference this while getting the value...


"SELECT @@DBTS as mydate"
0
 

Author Comment

by:cerebrumconsulting
ID: 35134064
Thanks, that was a help.  My problem was deeper, but I didn't know that when i wrote the question.

This is the final solution.  I had to declare the @@DBTS variable as a field (LastUpdate) as you suggested.

// Temp is the TADOQuery component
Unit Math;

var
  OrigValue :TBytes;
  Int64Representation :Int64;
begin
  Temp.Open;
  setlength(OrigValue, length(TempLastUpdate.AsBytes));
  OrigValue := TempLastUpdate.AsVariant; // .AsBytes gave a type mismatch even though both are declared as TBytes ???

   Int64Representation := OrigValue[0]
      + (OrigValue[1]*Round(IntPower(256, 1)))
      + (OrigValue[2]*Round(IntPower(256, 2)))
      + (OrigValue[3]*Round(IntPower(256, 3)))
      + (OrigValue[4]*Round(IntPower(256, 4)))
      + (OrigValue[5]*Round(IntPower(256, 5)))
      + (OrigValue[6]*Round(IntPower(256, 6)))
      + (OrigValue[7]*Round(IntPower(256, 7)));
   Caption := IntToStr(Int64Representation); // Show that we have actually retrieved a readable number
   Temp.Close;
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now