Tuesday 6 December 2016

Copy All tables with Data in Another Database

  1. CREATE PROCEDURE [dbo].[uspCreateCopyTables]-- GOALTEST,GOAL     
  2.     -- parameters for the stored procedure here    
  3.     @toDatabase VARCHAR(100)    
  4.     ,@fromDatabase VARCHAR(100)    
  5. AS    
  6. BEGIN    
  7.     -- SET NOCOUNT ON added to prevent extra result sets from    
  8.     SET NOCOUNT ON;    
  9.      
  10.     DECLARE @fullTableList VARCHAR(8000);    
  11.     DECLARE @idx INT;    
  12.     DECLARE @tableName VARCHAR(8000);    
  13.     DECLARE @SQLQuery NVARCHAR(500);    
  14.     DECLARE @ParameterDefinition NVARCHAR(100);    
  15.      
  16.     -- this  query gives the list of table name existing in the database.    
  17.     SELECT @fullTableList = ISNULL(@fullTableList + ',' + TABLE_NAME, TABLE_NAME)    
  18.     FROM INFORMATION_SCHEMA.TABLES    
  19.     WHERE TABLE_TYPE = 'BASE TABLE';    
  20.      
  21.     SELECT @idx = 1    
  22.      
  23.     /* this section splits the table name from comma separated string and copies that table name from      
  24.         one database to another database*/    
  25.     IF LEN(@fullTableList) > 1    
  26.         OR @fullTableList IS NOT NULL    
  27.         WHILE @idx != 0    
  28.         BEGIN    
  29.             SET @idx = CHARINDEX(',', @fullTableList)    
  30.      
  31.             IF @idx != 0    
  32.                 SET @tableName = LEFT(@fullTableList, @idx - 1)    
  33.             ELSE    
  34.                 SET @tableName = @fullTableList    
  35.      
  36.             IF (LEN(@tableName) > 0)    
  37.                 SET @SQLQuery = 'SELECT  * INTO [' + @toDatabase + '].[dbo].[' + @tableName + '] FROM [' + @fromDatabase + '].[dbo].[' + @tableName + ']'    
  38.      
  39.             EXEC (@SQLQuery)    
  40.      
  41.             SET @fullTableList = RIGHT(@fullTableList, LEN(@fullTableList) - @idx)    
  42.      
  43.             IF LEN(@fullTableList) = 0    
  44.                 BREAK    
  45.         END    
  46. END    
  47. GO   

Tuesday 29 November 2016

SignalR Examples

ChatHUBS.cs 

Code
  1. public void Send(string name, string message) {  
  2.     // Call the broadcastMessage method to update clients.  
  3.     Clients.All.broadcastMessage(name, message);  
  4. }  
Startup.cs

  1. public void Configuration(IAppBuilder app)  
  2. {  
  3.     // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888  
  4.     app.MapSignalR();  
  5. }  
Htmlpage

  1. <!DOCTYPE html>  
  2. <html>  
  3.   
  4. <head>  
  5.     <title></title>  
  6.     <style type="text/css">  
  7.         .container {  
  8.             background-color: #99CCFF;  
  9.             border: thick solid #808080;  
  10.             padding: 20px;  
  11.             margin: 20px;  
  12.         }  
  13.     </style>  
  14.     <meta charset="utf-8" /> </head>  
  15.   
  16. <body>  
  17.     <div class="container"> <input type="text" id="message" /> <input type="button" id="sendmessage" value="Send" /> <input type="hidden" id="displayname" />  
  18.         <ul id="discussion"></ul>  
  19.     </div>  
  20.     <!--Script references. -->  
  21.     <!--Reference the jQuery library. -->  
  22.     <script src="Scripts/jquery-1.6.4.min.js"></script>  
  23.     <!--Reference the SignalR library. -->  
  24.     <script src="Scripts/jquery.signalR-2.2.1.min.js"></script>  
  25.     <!--Reference the autogenerated SignalR hub script. -->  
  26.     <script src="signalr/hubs"></script>  
  27.     <!--Add script to update the page and send messages.-->  
  28.     <script type="text/javascript">  
  29.         $(function() {  
  30.             // Declare a proxy to reference the hub.  
  31.             var chat = $.connection.chatHub;  
  32.             // Create a function that the hub can call to broadcast messages.  
  33.             chat.client.broadcastMessage = function(name, message) {  
  34.                 // Html encode display name and message.  
  35.                 var encodedName = $('<div />').text(name).html();  
  36.                 var encodedMsg = $('<div />').text(message).html();  
  37.                 // Add the message to the page.  
  38.                 $('#discussion').append('<li><strong>' + encodedName + '</strong>:  ' + encodedMsg + '</li>');  
  39.             };  
  40.             // Get the user name and store it to prepend to messages.  
  41.             $('#displayname').val(prompt('Enter your name:', ''));  
  42.             // Set initial focus to message input box.  
  43.             $('#message').focus();  
  44.             // Start the connection.  
  45.             $.connection.hub.start().done(function() {  
  46.                 $('#sendmessage').click(function() {  
  47.                     // Call the Send method on the hub.  
  48.                     chat.server.send($('#displayname').val(), $('#message').val());  
  49.                     // Clear text box and reset focus for next comment.  
  50.                     $('#message').val('').focus();  
  51.                 });  
  52.             });  
  53.         });  
  54.     </script>  
  55. </body>  
  56.   
  57. </html>  
Hub connect check

  1. <script>  
  2.     $.connection.hub.start().done(function() {  
  3.         alert("Hub Connected");  
  4.     }).fail(function() {  
  5.         alert("Hub error");  
  6.     });  
  7. </script>  

Upload valid file in C#

    protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile)     {         try         {             Dictionary<string, byte[]>...