Wednesday, 25 October 2017

asp connect to sql and access

Monday, 27 February 2017

ASP Web Service

Sometimes you need to create a webservice .asmx, without use service reference and call this service via ajax request or other requests, you need to do the following


  • Right click on any folder you want to add the service to it and type the name of it.

  • After you hit OK, your code should locks like the following 
namespace ...
{
    ///
    /// Summary description for WebService1
    ///
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod(EnableSession = true)]// This to make this method accessible to public and access the web session in the link  
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]// to return the text as json
        public string HelloWorld(string x1, int x2)
        {
            return "Hello World";
        }
    }
}
  • To call HelloWorld method from jquery use the following code snippet 
      var x1='xxx', x2=20;    
 $.ajax({
            type: "POST",
            url: "/WebService1.asmx/HelloWorld",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: "{x1:'"x1+ "', x2:'" + x2"'}",
            beforeSend: function () {
                $('#loadingImage').show();//to show a loading image while ajax call in progress
            },
            success: function (data) {
                console.info(data.d);
            },
            complete: function () {
                $('#loadingImage').hide();
            },
            error: function (XMLHttpRequest, result, errorThrown) {
                console.info('error',errorThrown);
            }
        });

Wednesday, 16 November 2016

haier tv and minix

When you open Full HD video (1080p) on some Haier TVs the screen will keep flashin, sometime show and some time blue screen

to overcome this problem, go to settings>Playback settings > HDMI self-adaption> choose level 1 not level 2

Tuesday, 20 September 2016

DNN Clear Log

To clear the DNN Log from DB use the following scripts 

TRUNCATE TABLE sitelog;

delete EventLog
where EventLog.LogGUID in (

SELECT     el.LogGUID
FROM            dbo.EventLog AS el LEFT OUTER JOIN
                         dbo.ExceptionEvents AS ee ON el.LogEventID = ee.LogEventID LEFT OUTER JOIN
                         dbo.Exceptions AS e ON el.ExceptionHash = e.ExceptionHash);

truncate table schedulehistory;



To shrink the DB (minimize the log file -.ldf- size) use the following script 

ALTER DATABASE dbname SET RECOVERY simple; --To change the recovery model
DBCC SHRINKDATABASE (dbname, TRUNCATEONLY); -- shrink database
DBCC SHRINKDATABASE (dbname);
ALTER DATABASE dbname SET RECOVERY full; --To change the recovery model




OR use the following script 


IF EXISTS (SELECT * FROM sys.sysobjects WHERE id = object_id(N'[sys_currentDNNVersion]') AND Type = N'FN')
       DROP FUNCTION [sys_currentDNNVersion]
GO
-- --------- create tooling: ---------

CREATE FUNCTION [sys_currentDNNVersion]()
       RETURNS Int
AS    
BEGIN
       DECLARE @Vers Int;
       SELECT Top(1) @Vers = Major * 10000 + Minor * 100 + Build FROM [Version] ORDER BY CreatedDate DESC;
       RETURN @Vers;
END
GO


       -- Drop Foreign Key Constraints:
       DECLARE @fkName nVarChar(100) = Null;
       SELECT @fkName = name FROM sys.foreign_keys
        WHERE parent_object_id = OBJECT_ID(N'[ExceptionEvents]')
          AND Object_id IN (SELECT constraint_object_id 
                             FROM  sys.foreign_key_columns F
                                          JOIN  sys.columns C ON F.parent_object_id = C.object_id AND F.parent_column_id = C.column_ID
                                          WHERE C.Name = N'LogEventID');
       IF Not @fkName Is Null
             Exec(N'ALTER TABLE [ExceptionEvents] DROP CONSTRAINT [' + @fkName +'];');

       SET @fkName = Null;
       SELECT @fkName = name FROM sys.foreign_keys
        WHERE parent_object_id = OBJECT_ID(N'[EventLog]')
          AND Object_id IN (SELECT constraint_object_id 
                             FROM  sys.foreign_key_columns F
                                          JOIN  sys.columns C ON F.parent_object_id = C.object_id AND F.parent_column_id = C.column_ID
                                          WHERE C.Name = N'ExceptionHash');
       IF Not @fkName Is Null
             Exec(N'ALTER TABLE [EventLog] DROP CONSTRAINT [' + @fkName +']')

GO

-- Truncate tables:

       TRUNCATE TABLE [Exceptions]
       TRUNCATE TABLE [ExceptionEvents]
       TRUNCATE TABLE [EventLog]



       -- Recreate Foreign Key Constraints (using common naming):
       ALTER TABLE [ExceptionEvents]
         WITH CHECK ADD CONSTRAINT [FK_ExceptionEvents_EventLog]
             FOREIGN KEY([LogEventID])
             REFERENCES [EventLog] ([LogEventID])
         ON DELETE CASCADE;
        
       ALTER TABLE [EventLog]
         WITH CHECK ADD CONSTRAINT [FK_EventLog_Exceptions]
             FOREIGN KEY([ExceptionHash])
             REFERENCES [Exceptions] ([ExceptionHash])
         ON DELETE NO ACTION;

GO

DROP FUNCTION [sys_currentDNNVersion]

GO