How to Fire error from a Script Component in SSIS

by Fighter28. December 2013 21:44

Recently I was required to write script component(which I try not to use unless left with no option...anyways)

I needed to add try catch block and fire the error, if something went wrong. To my surprise, doing so was not that straight forward, hence posting

     try  

        {

            // Your Code here

        }

        catch (Exception ex)

        {

            bool fireError = true;

            IDTSComponentMetaData100 myMetaData;

            myMetaData = this.ComponentMetaData;

            myMetaData.FireError(0, "SubComponent", ex.ToString(), string.Empty, 0, out fireError);

        } 

Tags:

SSIS

Login Failed.Not associated with a trusted SQL Server connection

by Fighter23. November 2013 19:38

Couple of days back I was trying to login to remote SQL Server using SQL Server authentication. In-spite of using correct credential

I was getting below error

Cannot connect to <<Server Name>>.

------------------------------

ADDITIONAL INFORMATION:

 

Login failed for user '<<Login Name>>'. Reason: Not associated with a trusted SQL Server connection. (Microsoft SQL Server, Error: 18452)

 

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=18452&LinkId=20476

 

At first it looked to me like some permission issue with the SQL login. But after checking the details and verify that there was no issue with permission.

I looked at the Server Property. And then I realized that this is not the issue with permission.

 

Actual issue was that Authentication was set to Windows only. Hence although SQL login was created, it was not allowing user to connect using SQL Login

 

Solution:

Simple open the property window of the SQL Server Instance and under Security tab, set the Authentication from Windows Only to SQL Server and Windows

 

 

Hope this helps J

SMO Error: You must supply an existing Database object

by Fighter28. September 2013 12:02

Have you ever faced an error like You must supply an existing Database object. When using SMO to script the database.

Error:

Microsoft.SqlServer.Management.Smo.SmoExceptionType.InvalidSmoOperationException

You must supply an existing Database object.

 

static void Main(string[] args)

 {

   Server srv = newServer("(local)");

   srv.ConnectionContext.LoginSecure = true;

   srv.ConnectionContext.ConnectTimeout = 40;

   srv.ConnectionContext.Connect();

   Database db = newDatabase(srv,"master");

   Transfer transfer = newTransfer(db);

   transfer.Options.ScriptData = false;

   // TODO: Rest of the code follows(not required for current sample)

 }

 

I also faced this error recently while working on a project and realized that this can be solved if instead of trying to create SMO Database object,

Loop through the Server Class property Databases (which is of type SMO DatabaseCollection) and using this Database Object while initializing the Transfer Object.

 

static void Main(string[] args)

 {

   Server srv = newServer("(local)");

   srv.ConnectionContext.LoginSecure = true;

   srv.ConnectionContext.ConnectTimeout = 40;

   srv.ConnectionContext.Connect();

   Database db = srv.Databases.Cast<Database>().FirstOrDefault(dbs => dbs.Name.Equals("master", StringComparison.OrdinalIgnoreCase));

   ransfer transfer = newTransfer(db);

   transfer.Options.ScriptData = false;

   // TODO: Rest of the code follows(not required for current sample)

 }

 

Hope this helps!

How to add COM Component to ASP Application

by Fighter25. September 2013 10:43

This can be easily done using the REGSVR32 command.

Way to Register the DLL

1. Open command prompt, and navigate to the DLL location and run below

regsvr32 <name of dll>.dll

2. Open the command prompt and run regsvr32, but in below command, ensure to give the full path of dll.

regsvr32 <fullpath>\<name of dll>.dll

Way to Unregistering a DLL

1. Open command prompt, and navigate to the DLL location and run below

regsvr32 -u <name of DLL>.dll

2. Open the command prompt and run regsvr32, but in below command, ensure to give the full path of dll.

regsvr32 -u <fullpath>\<name of dll>.dll

How to read data from excel in QTP

by Softhacker22. July 2013 18:04

Sample Code:

Dim tsrows
'How to add run time sheet in QTP
datatable.Addsheet "dLogin"
'Import data from excel sheet to QTP  sheet
datatable.ImportSheet "D:\\NewFile.xls","LoginId","dLogin"
'Get row count
tsrows = datatable.GetSheet("dTCase").GetRowCount
print  tsrows
wait 10

Tags:

General

How to add Image to ASP.NET RadioButtonList

by Fighter18. July 2013 19:17

Below are the steps to create RadioButtonList with Images:
1. Create a folder in your solution and place all the images in it.
2. Create a foreach loop to loop through each items of the folder and create image tag.
3. Create a new ListItem and assign the image tag created in step 2.
4. Add this LsitItem to your RadiobuttonList.

Sample Code:

DirectoryInfo dir = new DirectoryInfo(Server.MapPath("Images//ReportImages"));
foreach (var file in dir.GetFiles())
{
     item = new ListItem("<img src='" + "Images/ReportImages/" + file.Name + "' alt='" + file.Name +
                                  "' title='" + file.Name + "'/>", Convert.ToString(i++));
      this.rptRadioListReport.Items.Add(item);
}

How to Rename a File and get the path of My Document in CSharp

by Fighter18. July 2013 19:03

How to Rename a File in C#:
Thinking of how to rename a file:
C# does not have anything like Rename Method.
Here is solution.
System.IO.File.Move(filePath, newFilePath);

How to get the path of My Documents in C#:
This is sometime needed when you want to write some file in My Documents folder.
System.Evironment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Above line of code gives you the path of My Document.

Error- The Role Manager feature has not been enabled:
Getting Error The Role Manager feature has not been enabled
This error occurs when you try to add/edit/Remove roles and you have not set the enable attribute of rolemanager section in web.config.
Search for tag roleManager in your web.config
<roleManager enabled="false">
and set the enable attribute to true.
<roleManager enabled="true">

Place Child Form in Center of Parent Form:
How to Place the Child form in center of Parent form:
This can be easily done by setting the StartPosition property of child form to FormStartPosition.CenterParent.

Sample Code:
PleaseWait pleaseWait = new PleaseWait();
pleaseWait.StartPosition = FormStartPosition.CenterParent;

Advantages of SQL Views

by Fighter18. July 2013 18:58

Advantages of View:

1.  It provides the means to abstract complex query from common user. Instead of writing a complex query every time you need. Better have a view created for the same and simple fire a select statement and get the desired data.
2.   View can be used to hide sensitive data from the users and group. Best and most common example is, if I have an Employee table with a column for salary and I want to hide this column from certain group.
In such case I will deny the access to Employee table for that group, Create a view that will have all columns but Salary. Grant access to the group on this view.
3.   Views also help is isolating the end users from the changes done to schema. Say for example I break down my Employee table into two parts to simply the operation. I can still keep my end user unaware of this change by just modify the view.

SQL Tip:
Ever faced a scenario where you needed to insert data into new table with data in one of existing table.
Here is this simple way to achieve this.
Table1 Columns -> A1, A2, A3
Table 2 Columns -> B1, B2, B3
If you want to insert data of table Table1 into Table2
Insert into Table2(A1,A2,A3)
Select B1, B2, B3 from Table1

How to write multiple lines string in JavaScript

by Softhacker18. July 2013 18:53

As a .NET developer, I was expecting something similar to "@" operator like C#  language to write multi lines string. But unfortunately I didn't get any such operator in JavaScript. There are two ways to write multi lines text in JavaScript. Refer below sample code:

//Cleaner way of writing multi lines text in JavaScript 

var multiLinesString = "First line\

                            Second Line\

                            ..\

                        ";

 

//Another way of writing multi lines text in JavaScript 

var multiLinesString = "First line"+

                            "Second Line"+

                            "..";

Below is the sample code to write multi lines text in C# (CSharp):

//Way to write multi lines text in C# 

string multiLinesString = @"First line

                                Second Line

                                ..

                            ";

 

//Another way of writing multi lines text in C#

string multiLinesString = "First line"+

                                "Second Line"+

                                "..";

 

Difference between primary key and unique key

by Softhacker18. July 2013 18:20

Difference between primary key and unique key are as follows-
1. A table contains only one primary key whereas it can have multiple unique keys
2. Primary Key can be defined only on NOT NULL columns whereas Unique Key can be defined on nullable columns
3. Primary key doesn't accept NULL Value where as Unique Key allows only one NULL Value
    Example-
Consider two attributes of an employee - Employee ID and Phone
Every employee has a different employee ID and employee ID cannot be null . So employee ID would become primary key but at the same time each and every employee also has a different phone number. However, we can allow one null value for a telephone number. So phone number field will become unique key.
4. Clustered index is created by primary key and Non-clustered index is created on unique key.

Note: Order of cluster index records are same as the physical order present in the table where as non cluster index is a special type of index where logical order of records do not match with physical order of records in table.

Like To Connect With US x