Wednesday, December 9, 2009

Convert DataReader To DataSet through C# Dynamically

Hi,

I was writing an application to read data from AS 400, Db2, based on the data I have to generate a report. I was trying to covert OdbcDataReader to DataSet. The following Code was helpful to do the same... We can use it for SqlDataReader as well.

Code:

public DataSet ConvertDataReaderToDataSet(System.Data.Odbc.OdbcDataReader reader)

{

DataSet dataSet = new DataSet();

do

{

// Create data table in runtime

DataTable schemaTable = reader.GetSchemaTable();

DataTable dataTable = new DataTable();

if (schemaTable != null)

{

for (int i = 0; i < schemaTable.Rows.Count; i++)

{

DataRow dataRow = schemaTable.Rows[i];

// Create a column name as provided in Schema

string columnName = (string)dataRow["ColumnName"];

// Define Column Type here

DataColumn column = new DataColumn(columnName, (Type)dataRow["DataType"]);

//Adding Column to table

dataTable.Columns.Add(column);

}

dataSet.Tables.Add(dataTable);

// Fill the data table from reader data

while (reader.Read())

{

DataRow dataRow = dataTable.NewRow();

for (int i = 0; i < reader.FieldCount; i++)

dataRow[i] = reader.GetValue(i);

dataTable.Rows.Add(dataRow);

}

}

else

{

// No records were returned

DataColumn column = new DataColumn("RowsAffected");

dataTable.Columns.Add(column);

dataSet.Tables.Add(dataTable);

DataRow dataRow = dataTable.NewRow();

dataRow[0] = reader.RecordsAffected;

dataTable.Rows.Add(dataRow);

}

}

while (reader.NextResult());

return dataSet;

}


Hope It Helpzzzz

4ZZZZ

Monday, December 7, 2009

Infopath System.Security. Permissions.EnvironmentPermission Fulltrust

Hey All,

When I tried to get current user in code behind in the infopath form, the following security exception occurred. The solution is we need to set Full trust for the Form.

Code used: nav.SelectSingleNode("//my:Myfield", NamespaceManager).SetValue(System.Environment.UserName);

Exception Message:
Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.Environment.get_UserName() at ItemCreation.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass6.<>c__DisplayClass8.b__1() at Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass6.b__0(Object sender, LoadingEventArgs e) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass34.b__30() at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.FireLoadingEvent(Document document, Dictionary`2 inputParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.PerformOnLoadEvent(Dictionary`2 intputParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.LoadSolutionAndDocument(HttpContext context, Solution solution, DocumentMetaInformation documentMetaInformation, OnInitializeCallback onInitializeCallback, OpenParameters openParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.OpenDocumentWithSolution(HttpContext context, SPSite contextSite, Solution solution, DocumentMetaInformation documentMetaInformation, OnInitializeCallback onInitializeCallback, OpenParameters openParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.NewFromSolution(HttpContext context, SPSite contextSite, Solution solution, DocumentMetaInformation documentMetaInformation, Boolean disableFirstRequestOptization, OnInitializeCallback onInitializeCallback, OpenParameters openParameters) at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.DataBindInternal(SolutionMetaInformation solutionMetaInformation, DocumentMetaInformation documentMetaInformation, String absoluteSolutionLocation, Boolean hasCloseHandler, Document& document) at Microsoft.Office.InfoPath.Server.Controls.FormServerPage.InitializeRenderInLine(SolutionMetaInformation solutionMetaInformation, DocumentMetaInformation documentMetaInformation, String absoluteSolutionLocation) at Microsoft.Office.InfoPath.Server.Controls.FormServerPage.NewEditingSession(SPSite contextSite, FormServerPageQueryParameters queryParameters) at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.StartNewEditingSession() at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.EnsureDocument(EventLogStart eventLogStart) at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.<>c__DisplayClass3.b__1() at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock) The action that failed was: Demand The type of the first permission that failed was: System.Security.Permissions.EnvironmentPermission The first permission that failed was: version="1" Read="UserName"/> The demand was for: version="1" Read="UserName"/> The granted set of the failing assembly was: version="1"> version="1" Flags="Execution"/> version="1" PublicKeyBlob="0024000004800000940000000602000000240000525341310
00400000100010083EF9CF1283A631F1C2513A36EA356E01870A92F21E61D5D53
1420B2C3905A6E3F8A0BD9E2BFAD3EAB3362877D233232ED1AE4836A1C51EAA7
717A16047A0F6F6E589F8689BCC5A15A20211252DB101B889228C5E15A3D49DC
2E112650853F16A85DD01652057E5D2CE7A41B01AA56576FFED4B4567FD8367
EE777C222C590E6"
Name="ItemCreation" AssemblyVersion="1.0.3628.18207"/> version="1" Url="file:///c:/inetpub/wwwroot/"/> version="1" Zone="MyComputer"/> version="1" Level="Minimal"/> version="1" Connections="True"/> The assembly or AppDomain that failed was: ItemCreation, Version=1.0.3628.18207, Culture=neutral, PublicKeyToken=f4d1ad1bba384fc7 The method that caused the failure was: Void FormEvents_Loading(System.Object, Microsoft.Office.InfoPath.LoadingEventArgs) The Zone of the assembly that failed was: MyComputer The Url of the assembly that failed was: file:///c:/inetpub/wwwroot/

How to set Permission: In Tools -> Form Options -> Security & trust -> Full Trust & Publish



Hope it Helpz

Thanks & Regards
Fauzi ~ 4Z

Sunday, December 6, 2009

How to read & write value from Infopath Datasource throught C#

Hi,

In a requirement, we need to display views based on the current user who updates the infopath form. So I thought let me write the logic to read and store values in Info path Data source from code behind. Following Code useful.

Read:
XPathNavigator nav = MainDataSource.CreateNavigator();
string fieldValue = nav.SelectSingleNode("//my:Myfield1", NamespaceManager).Value;

Write:
XPathNavigator nav = MainDataSource.CreateNavigator();
nav.SelectSingleNode("//my:Myfield1", NamespaceManager).SetValue("NewValue");

essential Namespace is Microsoft.Office.InfoPath;

Hope it helps...

Best Regards
Fauzi ~4Z

Monday, November 30, 2009

Publish Infopath form with CodeBehind

Hey,

When I publish a normal infopath form without code behind, I was able to publish them from Info path editor it self and on click of 'New' in forms library, i was able to view the form in the Browser. But when i tried to publish with Codebehind and Click 'New' the form only opened in a New editor!

When i googled for the same, came to know that when we add code behind logic (say with C#) first we need to publish and later we need to approve the info path form through Sharepoint Administration.

There are four steps to be implemented:

  • Publish the Template to the File System
  • Upload the Template to Central Administration Form Templates Library
  • Activate the Form Template in your Site Collection
  • Associate the Form Template with the Form Library
It is clearly given in the following Link: Click
Its very helpful...


Thanks
Fauzi

Monday, November 9, 2009

Sample to display Image on mouse hover.

Created the following sample for one of a small web requirement.

Hosting it since it could be useful for some one who is looking for it...

Sample Link: http://checkthiz.com/publicfiles/ImageHover.html

Hope it helps

Fauzi ~ 4Z

How to connect to SQL Server Desktop Engine Remotely

Hi all,

Lesson learnt for the day is when you try to connect to SQL Server Desktop Engine (MSDE) remotely, the scenario where i tried to connect was from SSIS - Sql Server Integration Services. I tried to create a OLEDB connection. When i tried to create the OLEDB connect the same like we use to do for SQL server; the following error message was shown



Solution: When i googled, came to know that we need to give the Server name with instance name when we create a connection.

like: <ServerName>/<InstanceName>
And we need to give the database name if not displayed in drop down list.

Hope It helps

Regrads
Fauzi ~4Z


Sunday, November 8, 2009

MOSS: document-library file upload limitation

Hi,

When we created shared folder for our business users, I had a doubt about the file upload limitations which might occur when our users upload files. When i googled for the same found that the default size is set to be 50MB (maxRequestLength="51200"). and to increase the limit we just need to configure the xml file in the following location

Solution:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\web.config

Config file:
<location path="upload.aspx">
<system.web>
<httpRuntime maxRequestLength="2097151" />
</system.web>
</location>

Resource: http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=8

Hope it helps

Regards
Fauzi ~4Z

Saturday, October 24, 2009

SQL: comparision of SQL Server Databases 2005

hi,

Here is the comparisons of different types of SQL Server 2005 databases in terms of Scalability and Performance, High Availability, Manageability, Security, Programmability, Integration and Interoperability,Business Intelligence

Resource : http://www.microsoft.com/Sqlserver/2005/en/us/compare-features.aspx

Hope it helps

Regards
4Z ~ Fauzi

Wednesday, October 21, 2009

MOSS: Email Notifications and Alerts problem in Tasks

Hi...

We had a mysterious problem in MOSS sharepoint portal in Tasks.
Following were the issues:
1. When ever a task is created; the alerts goes to people(some one in AD) for whom the tasks has not been assigned!
2. When ever edited also the same issue Plus the description will be striked & shown as such it has been changed.
3. When the tasks is deleted; the alert goes to the respective persons in the assigned to field and also to some other person in random!

Task Assigned to

Solution:
Seems it is resolved in SP2 and there is also a Hotfix for the same issue.

Resource: http://social.msdn.microsoft.com/Forums/en-US/sharepointgeneral/thread/398f0a1d-621b-4813-a64a-4065d35c0842

Hotfixes:
http://support.microsoft.com/kb/948945

http://support.microsoft.com/kb/948947

Hope it helps...

This is My 100th post, Thanks for your continuous support :)

Regards
Fauzi


Wednesday, October 14, 2009

MOSS: How to disable checkin option in document Library

Hey...

We had a requirement to disable checkin functionality in document library. The Idea was to reduce the steps to be done by the end user to upload documents easily. The bottom line was to make it simple for easy accessibility. Following are the steps to be done.

To enable/disable check-in and check-out on a SharePoint document library:

  1. Navigate to the SharePoint document library on which you want to enable check-in and check-out.
  2. On the Settings menu, click Document Library Settings .
  3. On the Customize page under General Settings , click Versioning settings .
  4. On the Document Library Versioning Settings page, select Yes /No for Require documents to be checked out before they can be edited? , and click OK .

To enable version control on a SharePoint document library:

  1. Navigate to the SharePoint document library on which you want to enable version control.
  2. On the Settings menu, click Document Library Settings .
  3. On the Customize page under General Settings , click Versioning settings .
  4. On the Document Library Versioning Settings page, select Create major versions if you only want to enable major versions on documents or select Create major and minor (draft) versions if you want both major and minor versions on documents, and click OK .

Reference

Hope It helps...

Fauzi 4z

Thursday, October 8, 2009

How to run a DTSX Programmatically through C#

Hey there...

For a data integration service, I create four DTSX packages. These were generic packages which needs to be executed one after the another. I tried using SQL Server Agent to schedule it as a JOB which has four steps to be executed sequentially. Unfortunately the package which is working fine is visual studio is not working when scheduled. There seems to be some permission issues(had the same issue few days before). As i had users waiting the see the output. I have to find an alternative solution soon. Here is the C# code to run the DTSX from a EXEC file.


Code:

Package pkg;

Application app;

DTSExecResult pkgResults;

Variables varStore;


pkgLocation = @"c:\documents and settings\Path\Filename.dtsx";

app = new Application();

pkg = app.LoadPackage(pkgLocation, null);

varStore = pkg.Variables;

varStore[YourVariable].Value = 123;

pkgResults = pkg.Execute();


Required NameSpace: The reference of Microsoft.SQLServer.ManagedDTS.dll has to be added and in code -

using Microsoft.SqlServer.Dts.Runtime;


Hope it helps :)