Author Archives: Yuriy

TSQL: Filling missing date range

Let’s say you have a table with some dates and numeric values e.g.:

2011-08-19	16
2011-08-22	45
2011-08-24	62
2011-08-25	88
2011-08-27	17
2011-08-28	35
2011-09-01	10
2011-09-02	79
2011-09-03	70
2011-09-07	83

As you can see not all dates are in the sequential order, 24th comes after 22nd etc. But in many cases you need this data to be sequential, for example if this data feeds a chart you need to fill it with missing dates and 0 for a value. There is an easy way to achieve this. Continue reading →

Solution for ASP.NET access to temporary folder denied error

Scenario: You’re trying to run an ASP.NET application when suddenly an error is thrown similar to this:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0016: Could not write to output file ‘c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\……..\………\some_code.dll’ — ‘Access is denied. ‘

You gave that folder all possible permissions imaginable and still the error persist. What the? Continue reading →

Elusive “String or binary data would be truncated” error

This was driving me nuts. I have a very basic SQL code similar to

ALTER PROCEDURE Proc1(@val1 NVARCHAR(max))
AS
BEGIN
    -- some code
    EXEC Proc2 @val2 = @val1
    -- some other code
END

I was getting error “String or binary data would be truncated”, but only when 2 conditions were met:

  1. @val1 is quite large
  2. Either SQL Server/computer just restarted or stored procedure Proc2 was just updated (ALTER)

Error happened just by the fact of the EXEC Proc2 being there it didn’t even had to do anything, it could RETURN straight away. Both @val2 an @val1 are of a type NVARCHAR(max) so there is no reason for the error. The error happened only once, after that I can pass data of any size – and no error would happen. Like I said – nuts. Continue reading →

Use symlinks to serve subdomain content

When you add a subdomain to your site, many hosting providers will automatically create a new physical folder on the server to match the subdomain name and to serve the subdomain content from. Which is all fine and good if your subdomain has a completely different content from main site/other subdomains.

But there’re situations when you need several subdomains to point to the same physical folder. Case in point: WordPress multisite install. There’s only a single installation of WordPress software, but depending on how you access it – it will serve different content. For example if you visit http://kitchen.galanter.net you will see a culinary blog, but if you open http://codecorner.galanter.net – a programming content will be served to you. This is achieved by WordPress by reading host header information (HTTP_HOST) and depending on header name (“kitchen” or “codecorner”) different content will be served. But it will be served from the same physical folder

Many hosting providers allow you to select root folder for the subdomains – in this case it’s easy: just add subdomain, point it to the root folder of the main domain and you’re done. But some, like my current host hard-code subdomain-subfolder relationship and it’s not allowed to change. In my case my root domain (which serves http://www.galanter.net) is physically located in /galanter.net/public folder. When I added subdomain codecorner, provider automatically created folder /galanter.net/codecorner/public which would have a completely different content, but I needed its content to be served from main /galanter.net/public folder, just pass “codecorner” HTTP host header to it. Enter symlinks. Continue reading →

CheckListBox to comma-separated string

Today I needed to do a simple thing: Combine selected values of .NET CheckListBox control into a comma separated string. I am lazy, so I decided to Google for a ready-to-use piece of code. Sure enough there’re tons of those. But all of them involve looping through control items, checking IF item is selected, then adding values.. Boring, routine stuff.

People! We live in the 21st century, age of inspiration! Uhm.. sorry, got carried away. Bottom line: I didn’t like any of those solutions and being a fan of LINQ I put together one of my own. Continue reading →

SQL Server stored procedure runs slow from .NET code

This has probably been discussed a lot before, but just in case here it is again, possible solution for following scenario:

You’re calling SQL Server stored procedure from your .NET code and it runs extremely slow. When you run same SP with exactly the same parameters (as captured by SQL Server Profiler) directly in SQL Server Management Studio, it runs very fast. What gives?

Chances are – that SP was executed before and query plan was cached for the specific parameters. To avoid this add WITH RECOMPILE option to your CREATE PROCEDURE or ALTER PROCEDURE statement. This will force SQL Server to create a new query plan every time SP runs, perhaps adding slight overhead, but creating an optimized path that will cover that overhead tenfold.

WebHierarchicalDatagrid: Sys.ArgumentException: Cannot deserialize on Row Expand

I have been using WebHierarchicalDataGrid with manual load on demand bands with a pretty good success until I hit this snag.

The WHDG has correctly displayed HTML fields before, but this time a column with HTML data (an HREF link to be precise) is needed as one of the grid’s DataKeyFields to provide uniqueness of the row:

WHDG with HTML column Continue reading →

Solution for “OraOLEDB.Oracle Provider is not registered” error

While connecting from an ASP.NET application to an Oracle database via OLEDB I got following error:

OraOLEDB.Oracle Provider is not registered on the local machine

Now I know that the driver was installed and registered. I downloaded an official driver from Oracle WebSite. In my case it was ODAC112021Xcopy_x64.zip 64-bit version for XCopy deployment. It installs in 2 easy steps:

  1. Unzip downloaded file into any folder
  2. Run (as administrator) command: INSTALL TYPE PATH NAME DEPENDANCIES

Where

  • TYPE – type of installation (e.g. OLEDB, basic etc.)
  • Path – where you want driver installed
  • Name – Oracle home name
  • Dependencies – true/false whether to install dependencies (e.g. instant client)

So my command was

INSTALL ALL “C:\Program Files\Oracle64Driver” Oracle64Driver TRUE

Which copied the files and created correct Registry entries (I checked). And still I was getting the error. I Googled it (a lot) but majority of suggestions was that the error is due to Windows ACL and correct permissions should be set on the driver folder. Didn’t help me.

So I fired up trusted ProcessMonitor and it showed that W3WP.EXE (ASP.NET process) was trying to access missing OCI.DLL file in the path C:\Program Files\Oracle64Driver\Bin, e.g. in the Bin folder of the path were the driver was installed. Looking back at the place were I unzipped the original driver files I found that DLL inside of “instantclient” folder. So I copied entire content of that folder into Bin folder at the destination. And Voila! The error disappeared.

Apparently Instant Client files aren’t copied by the installer even when Dependencies option is set to true.

Solution for UltraWebGrid missing scrollbars

I was working with classic Infragistics UltraWebGrid when noticed strange thing – even though scrollbars were enabled for the grid, the grid had fixed size and number of rows was bigger than the grid could display – no scrollbars appeared. For me it was a combination of grid being shown in a modal dialog in IE7 browser, but it could happen in other scenarios.

I also noticed when grid experienced any kind of user interaction (row added, row selected, checkbox cell checked etc.) scrollbars would magically appear. So the solution? Simulate user interaction. For example this code can be included in grid’s client-side InitializeLayout event:

function xMyGrid_InitializeLayout() {
    var oGrid = igtbl_getGridById('xMyGrid')
    oGrid.Rows.getRow(0).setSelected(true);
    oGrid.Rows.getRow(0).setSelected(false);
}

What happens here is first row of the grid is selected and an instant later unselected. It happens so fast that there’s no visual indication. But the grid gets its “user interaction” and scrollbars appear.