Friday, August 31, 2007

.NET Web Service error - "The test form is only available for requests from the local machine"

I faced this error before.
I used my local pc's window service application to call a web service function at server (different pc) but it is fail. It cannot work like when I used the same window service application to call the same web service function at local pc.

Then, I tried to browse to the web service through ie. When I click the fuction, it showed the message - "The test form is only available for requests from the local machine"

After that, I found the solution to fix it. I just added in some code inside the
web.config file then the this problem is solved. The code I added in is like below:

<configuration>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
  </system.web>
</configuration>

Thursday, July 26, 2007

SQL Server function for datetime - DATEADD

DATEADD is a date function will return a datetime value based on the number interval add to the particular date part of the specified date. The syntax DATEADD is like:

DATEADD(date_part, number_interval, specified_date)

date_part is the parameter that specifies on which part of the date to be manipulated with the number interval. You can add month, year, day and etc. You can use
MONTH, MM or M for month
YEAR, YYYY, YY for year
DAY, DD, D for day
HH for hour
SS, S for Second

For example :
SELECT DATEADD(D, -1, GETDATE())AS [Yesterday]
SELECT DATEADD(MM, 3, GETDATE())AS [FourMonthsFromNow]
SELECT DATEADD(YEAR, -2, GETDATE())AS [TwoYearsAgo]