Skip to main content

Posts

Showing posts from 2018

SSIS package - set oledb connections at runtime

SSIS oledb connection manager does't allow user to connect to different oledb servers. If we store oledb connection sting in Config file then it will accepts server name, InitialCatalog and username. But it wont accept password. The is because oledb connection manager has not exposed the oledb password property. To over come this problem we have to override the OLEDB connection manager itself. So that it accepts connections to different oledb servers. Public Sub Main() Dim vars As Variables Dim oledbConnectionManager As ConnectionManager oledbConnectionManager = Dts.Connections("<oledb connection name>") ' ADDED TO MAKE oledb CONNECTION STRING DYNAMIC Dim oServerName As String Dim oUserName As String Dim oInitialCatalog As String Dim oPassword As String Dts.VariableDispenser.LockOneForWrite("oServerName", vars) oServerName = vars("oServerName").Value.ToString().Trim() vars.Unlock() Dts.VariableDispenser.LockOneForWrite("oInitia

SQL query - Table rows as columns

-- Create a table variable to store user data DECLARE @myTable TABLE (    UserName VARCHAR(50),    ArticleName VARCHAR(50) ) -- Insert some data to table to work on that data INSERT INTO @myTable(UserName, ArticleName) VALUES ('Jack', 'ASP.NET') INSERT INTO @myTable(UserName, ArticleName) VALUES ('Jack', 'SQL Server') INSERT INTO @myTable(UserName, ArticleName) VALUES ('Jack', 'C#') INSERT INTO @myTable(UserName, ArticleName) VALUES ('Jack', 'VB.NET') INSERT INTO @myTable(UserName, ArticleName) VALUES ('David', 'Java') INSERT INTO @myTable(UserName, ArticleName) VALUES ('David', 'Java Beans') INSERT INTO @myTable(UserName, ArticleName) VALUES ('David', 'Java script') SELECT UserName, ArticleName FROM @myTable -- This is how the table looks after inserting the data Now I want all the articles related to Jack and David in a single column.

SQL query - Table sorting

In this article we will learn how to sort the table values with out using dynamic query to improve performance. CREATE PROCEDURE SortingExample ( @sortFiled INT, @sortType INT  -- 1 for ASC, 2 for DESC ) AS BEGIN -- Create a table variable to store user data DECLARE @myTable TABLE ( UserID INT IDENTITY(1,1), UserName VARCHAR(50), Password VARCHAR(50), Email VARCHAR(50) ) -- Insert some data to table to work on that data INSERT INTO @myTable(UserName, Password, Email) VALUES ('Jack', 'JackPwd', 'jack@gmail.com') INSERT INTO @myTable(UserName, Password, Email) VALUES ('Anand', 'AnandPwd', 'raj@gmail.com') INSERT INTO @myTable(UserName, Password, Email) VALUES ('smith', 'smithPwd', 'smith@gmail.com') INSERT INTO @myTable(UserName, Password, Email) VALUES ('Brandy', 'BrandyPwd', 'tom@gmail.com') -- If @sortType = 1 then sort the selected field in ASC ord

SQL query - Iterate through table records without using cursor

In this article we will see ow to loop through the rows of a table without using cursor In this article I will explain how to loop through each rows in a table and get the data one by one for processing. -- Create a table variable to store user data DECLARE @myTable TABLE (     UserID INT IDENTITY(1,1),     UserName VARCHAR(50),     Password VARCHAR(50),     Email VARCHAR(50) ) -- Insert some data to table to work on that data INSERT INTO @myTable(UserName, Password, Email) VALUES ('Jack', 'JackPwd', 'jack@gmail.com') INSERT INTO @myTable(UserName, Password, Email) VALUES ('Raj', 'RajPwd', 'raj@gmail.com') INSERT INTO @myTable(UserName, Password, Email) VALUES ('smith', 'smithPwd', 'smith@gmail.com') INSERT INTO @myTable(UserName, Password, Email) VALUES ('Tom', 'tomPwd', 'tom@gmail.com') -- Get the number of rows in the looping table DECLARE @RowCount I

SQL Query - Parsing comma separated string

In this article we will see how to separate data one by one from a comma separated string. First declare a variable to store articles in comma separated values. DECLARE @DataString VARCHAR(200) SET @DataString = 'ASP.NET, VB.NET, C#.NET, SQL, Javascript' Add comma at last to @DataString SET @DataString = @DataString + ',' Using while loop through all the topics in @DataString WHILE (CHARINDEX(',', @DataString) > 0) --  CHARINDEX  is a SQL inbuilt function which returns the integer value if charecter is present in a string. BEGIN         -- To hold each topic         DECLARE @Topics VARCHAR(30)         -- Get the topic one at a time                SET @Topics = SUBSTRING(@DataString,0, CHARINDEX(',', @DataString))         PRINT @Topics             -- Reset the @DataString         SET @DataString = SUBSTRING(@DataString, CHARINDEX(',', @DataString) + 1, LEN(@DataString)) END Here is the out put of the above query   ASP.NET  V

SSIS - Error handling

In this article we will learn how to handle the errors in SSIS package. In SSIS when package throws an error then these error details is stored in following variables ErrorCode, ErrorDescription and SourceName. Below is the code to handle error in SSIS package. When a SSIS task encounters an error these error details are stored in three system variables. Dts.VariableDispenser.LockForRead("ErrorCode") Dts.VariableDispenser.LockForRead("ErrorDescription") Dts.VariableDispenser.LockForRead("SourceName") ErrorCode variables returns error code which will be numeric. ErrorDescription will give us a brief description of an error encountered by the SSIS task. SourceName give us the task name from which error occured. Private Sub GetErrorValues(ByRef errNumber As Integer, ByRef errDescription As String, ByRef errSource As String)                     Dts.VariableDispenser.LockForRead("ErrorCode")             Dts.VariableDispenser.L

Code to embed an image in e-mail

In this code we will learn how to embed an image in mail using VB.NET. Public Sub SendMail(ByVal message As String)         Dim vars As Variables         Dim myHtmlMessage As MailMessage         Dim mySmtpClient As SmtpClient         Dim retVal As Int32 = -1         myHtmlMessage = New MailMessage()         Dim FromAddress As String         Dts.VariableDispenser.LockOneForWrite("from", vars)         FromAddress = vars("from").Value.ToString().Trim()         vars.Unlock()         Dim ToAddress As String         Dts.VariableDispenser.LockOneForWrite("to", vars)         ToAddress = vars("to").Value.ToString().Trim()         vars.Unlock()         Dim CCAddress As String         Dts.VariableDispenser.LockOneForWrite("cc", vars)         CCAddress = vars("cc").Value.ToString().Trim()         vars.Unlock()         Dim SmtpClient As String         Dts.VariableDispenser.LockOneForWrite("smtpServer&quo

Sending email in SSIS using script task

Sending mail using script task. We can send email with attachments and also either in text format or in HTML format Public Sub SendMail(ByVal message As String)         Dim vars As Variables         Dim myHtmlMessage As MailMessage         Dim mySmtpClient As SmtpClient            myHtmlMessage = New MailMessage()         Dim FromAddress As String         Dts.VariableDispenser.LockOneForWrite("from", vars)         FromAddress = vars("from").Value.ToString().Trim()         vars.Unlock()         Dim ToAddress As String         Dts.VariableDispenser.LockOneForWrite("to", vars)         ToAddress = vars("to").Value.ToString().Trim()         vars.Unlock()         Dim CCAddress As String         Dts.VariableDispenser.LockOneForWrite("cc", vars)         CCAddress = vars("cc").Value.ToString().Trim()         vars.Unlock()         Dim SmtpClient As String         Dts.VariableDispenser.LockOneForWrite("

ASP.NET Cache dependency example

In this article we will learn how to implement file dependency in caching. In this method the cache["messageDependency"]  loads the file "DependencyFile.txt" in memory(cache) only when its content is changed in the disk. public void displayMessage() {          String message;          String Path = "~/DependencyFile.txt";          if (Cache["messageDependency"] == null)          {                   System.IO.StreamReader sReader = new StreamReader(Server.MapPath(Path));                   message = sReader.ReadToEnd();                   sReader.Close();                   System.Web.Caching.CacheDependency msgDependency = new System.Web.Caching.CacheDependency(Server.MapPath(Path));                   Cache.Insert("messageDependency", message, msgDependency);          }          Response.Write(Cache["messageDependency"].ToString()); }

Explore Kaazing Websocket in .Net

Introduction Kaazing WebSocket Gateway provides full duplex web communication. It provides an alternate way of communication from server to client for “polling” or “long-polling”. WebSocket WebSocket is a full-duplex single socket connection over which messages can be sent between a client and a server. The WebSocket standard simplifies much of the complexity around bi-directional web communication and connection management. Kaazing WebSocket Kaazing WebSocket Gateway is an HTML5-compliant WebSocket server with support to today's pre-HTML5 browsers. The Gateway provides a bridge between WebSocket clients and your back-end systems, servers, and applications. This enables you to implement your own custom protocol or run an existing protocol over WebSocket. Installing Kaazing WebSocket 1.         Kaazing WebSocket can be installed in Windows 7, Windows Vista, Windows XP SP3 2.         Download the full Kaazing WebSocket Gateway - HTML5 Edition from the