Friday, July 9, 2010

CopyToDataTable: LINQ to DataSet

Linq has a built in CopyToDataTable() method to convert resultset of a LINQ query to DataTable. This works fine if the query returns DataRow type. But surprisingly they don't work if a LINQ query implements a JOIN.
For example, the resultset of following query can not be converted into a DataTable using CopyToDataTable() method.
var final = from s in sourceTable.AsEnumerable()
join d in destinationTable.AsEnumerable() on s.Field("Id1") equals d.Field("Id2")
select new { Name = d.Field("Name"), Zip = s.Field("Zip"), Error = d.Field("Error") };


After a bit of toiling I found that to achieve this it will require implementation of an extension method. It was described here:
http://blogs.msdn.com/b/aconrad/archive/2007/09/07/science-project.aspx

And also on MSDN

I was using the CopyToDataTable() method over other queries too and implementation of the extension methods as suggested above resulted in exceptions where the method was called earlier.

I figured it will be safe if I rename the extension methods to avoid ambiguity. And that also helped the earlier exception to go away.

Tuesday, April 20, 2010

Using themed css files requires a header control on the page. (e.g. head runat="server" ).

A search with the title text yields thousands of results each with almost similar solutions:
a.) Put the
tag on the page.
b.) Set EnableTheming = "False" on page. But this in itself doesn't work. Another workaround I saw was set StylesheetTheme="" Theme="" on the page. Even this didn't do the trick.

What worked for me was the comment on MS Connect page: http://connect.microsoft.com/VisualStudio/feedback/details/102039/using-themed-css-files-requires-a-header-control-on-the-page-e-g-head-runat-server">

So I added a web.config in the folder where I had the page that was throwing an exception and insert
< pages theme="">


My page was using MS Virtual Earth and this error would block my custom code to be called from the Mapping.js file to display the push pins on the map.

Tuesday, July 28, 2009

Setting Default button in ASP

The other day I saw a posting on a forum about setting Default button for a web form. Till that day I had not tried that thing out (I just vaguely remembered that there's something like a DefaultButton property). So when I created a simple form with a text box, button and a gridview wrapped in an Update Panel, I just couldn't locate the property anywhere (no property in asp:Button tag, no this.DefaultButton). Then I read that to achieve the default button property you need to do:
ClientScript.RegisterHiddenField("__EVENTTARGET", submitButton.UniqueID);
Once the code was in place and I hit the "enter" key and lo and behold another cryptic error
Microsoft JScript runtime error: 'this._postBackSettings.async' is null or not an object
Then I read on another blog that you need to put a panel around and set the DefaultButton property value. Though this was not the response I was looking for but I got an idea as to where to look for the DefaultButton thing. So, I removed my ClientScript.RegisterHiddenField code and set the
defaultbutton="submitButton"
in form tag. And that was it!

Thursday, July 16, 2009

Sys.WebForms.PageRequestManager error

While creating a new .Net 2.0 project I encountered something that had never happened to me when creating other ASP.Net web applications.

I had this new ASP.Net web application and I put in a script manager in the Master Page and an update panel in one of the content pages. When running this simple setup I got an error that had never happened before
Sys.WebForms.PageRequestManager._initialize Microsoft JScript runtime error: 'Sys' is undefined
This left me a bit confused but a bit of search on the web and I realized that there were some key values missing from the web.config.

Other projects that I had created were taken as AJAX enabled template projects and hence never posed any issue. The solution was to create a new ASP.Net AJAX enabled web application and then copy-paste the relevant sections from the new project in your web.config.

SSIS: Changing connection string in Data flow dynamically

Recently I was developing an SSIS package where I had to source data values from Oracle and SQL Server. The SSIS package had multiple For..Loop containers to mimic threading structure in SSIS. Since, at design time I couldn't identify which SQL query (the source) would execute in which For..Loop container, I decided to source the connection string from a table in my SQL Server and then assign it to the OLEDB source at runtime.

For package validation purposes, I had an Oracle connection assigned to the OLEDB source at design time.

Everything works fine till here. But when I ran the package, I found that it will throw an error
Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14. An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E14 Description: "Statement(s) could not be prepared.". An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E14 Description: "Invalid object name 'MyTable'".

And
[DTS.Pipeline] Error: "component "Alert values from Oracle" (585)" failed validation and returned validation status "VS_ISBROKEN".
After much turmoil I found that for some weird reason the "Initial Catalog" value assigned in the connection string for SQL Server doesn't work as expected. And since the schema assigned to the package user would connect to Master database it couldn't locate the table mentioned.

Solution: Use the absolute table path in the FROM clause like
select column1 from dbname.schema.mytable
And that did the trick.

Tuesday, June 16, 2009

SQL Server 2005 & Blue Screen

I had almost forgotten that the "blue screen" of death exist till I started staring at it for the past couple weeks.

I have taken up a new assignment and was given a Lenovo Thinkpad (I hate working on laptops) to carry out my assignment. So to make myself comfortable I bought a MS wireless keyboard and mouse. And there it was, I started getting the blue screen every once a while.

It took me a while to realize that this would happen only when I work with SQL Server 2005 and do a "Open Table". The grid lines will blur and randomly the system will crash. This didn't happen everytime but whenever it happened that is what I was doing.

Looking it up on www.bing.com (yes some people are using it) gave me http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=258813 which had a few workarounds. And one of them was uninstalling the driver for the wireless MS mouse that I had bought. That did the trick for me too.

Kill the ipoint.exe and uninstall the driver.

I talked to another colleague of mine and he had the same issue. His was due to some NVidia drivers. He disabled it from Control Panel > NVidia Desktop Manager. That did the trick for him.

Wednesday, October 15, 2008

Update Panel intricacies

While experimenting with multiple update panels on a single page there were certain weird things that I observed.
1.) Duplicate controls created: I had placed a label within an update panel like below:
< tr >
< asp:updatepanel id="UpdatePanel3" runat="server" updatemode="Always" rendermode="Block">
< contenttemplate>
< td colspan="2">
< asp:label id="Label1" runat="server" text="Test Label">
< /td>
< /contenttemplate>
< /asp:updatepanel>
< /tr>


And somewhere else in the page:

< tr>
< td style="WIDTH: auto">
< asp:dropdownlist id="DropDownList1" runat="server" autopostback="true">
< asp:listitem>One
< asp:listitem>Two
< asp:listitem>Three
< asp:listitem>Four
< asp:listitem>Five
< /asp:dropdownlist>
< /td>
< td style="WIDTH: auto">
< asp:updatepanel id="UpdatePanel2" runat="server" updatemode="Conditional">
< contenttemplate>
< asp:textbox id="TextBox1" runat="server">
< /contenttemplate>
< triggers>
< asp:asyncpostbacktrigger controlid="DropDownList1" eventname="SelectedIndexChanged">
< /triggers>
< /asp:updatepanel>
< /td>
< /tr


Now whenever an AJAX postback happened, the page will have two lables shown to it. I found that if put the property RenderMode="Inline" in UpdatePanel1, the label is no more duplicated. It would be worth noting that the "Block" RenderMode renders two labels, as well. In the source of the HTML I found that the "Inline" mode renders the UpdatePanel in < span>tags while the "Block" mode renders the UpdatePanel in < div>tags.

The problem goes away if the < td>is wrapped around the UpdatePanel. So after modifying the first HTML to

< td colspan="2">
< asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Always">
< contenttemplate>
< asp:label id="Label1" runat="server" text="Test Label">
< /contenttemplate>
< /asp:updatepanel>
< /td>


I do not need to explicitly set the RenderMode value to "Inline".

But why it happens? No idea.