Friday, November 05, 2010

MarkLogic, Restful Service, etc

This post is used to summarize all resource for marklogic database, REST web serivces and other related technologies needed for my new job.

Monday, October 25, 2010

DataList and ViewState

It could be either intended or an issue of ASP.NET, but the bottom line is the ViewState is not available for DataList control! Therefore, page after posting back will find datalist lost its viewstate. The solution is:
  1. save controls' status into session. (controls here is the controls inside datalist control)
  2. using OnItemDataBound(...) function to reload status info from session

Tuesday, August 17, 2010

execute dynamic query from stored procedure

After realized the crazy requirements of the site locator program, I know a common store procedure won't work. However, because of our database name is different in each enviorment (staging, QA, prod), the dynamic query in the code won't work either. The only solution is to use sp to run dynamic query. the sql syntax looks like this:

EXECUTE SP_EXECUTESQL @sqlStatement

where @sqlstatement is nvarchar (max 4000 charaters). The caveat here is 4000 is really short, and a long/complex query will easily exceed this limit.

Friday, February 26, 2010

MVC study and thoughts

First of all, I think MVC is a big deal. It separate concerns of data layer, business layer and presentation layer. If used well, it will generate much cleaner and maintainable code than regular web form. However, I found MVC falls short in the following areas:
  • report. it always seems to be true: a report should just stay simple instead of trying any other advanced approaches such as TDD or MVC. In the end, it's just report which represents data directly from the data layer, and most likely with lots of fancy staff on the UI
  • dynamic HTML (with input). if you don't know how many controls you page will have to generate, and also you are expecting inputs from these controls, it's challenging using MVC.
  • JQuery in custom while using AJAX, this seems like not a big issue and not directly related to MVC, but since MVC use AJAX and Jquery a lot, so just be aware

Monday, November 16, 2009

Speech server application and Cache

In the speech server application I am creating, I need to load some data and save it into the Cache so every call can share that data in a readonly fashion. The normal way for me to access Cache is to use HttpContext.Current.Cache. However, HttpContext.Current is null in speech server application. I tested in both IIS 5.1 and 6.0 with soft and regular land phone. I then began to use WorkFlow.UserData as the application Cache. It works fine except you can't set its expiration time. After a little research and I found that I can acutally access Cache by HttpRuntime.Cache, and it even performance a little better. A good article to compare these two different way of accessing Cache is here.

Friday, November 13, 2009

speech server running under iis 5.1

It seems like the speech server is only designed to run under iis 6.1 or higher. According to this reference: It "Setup program creates an application pool called Speech Server under which Speech Server applications are intended to run". and by default "The Speech Server processes run as the NETWORK SERVICE account". It should use this default account when accessing local resource and use current windows account to access network resource (such as database and shared file server).
However, the IIS 5.1 doesn't have application pool and web app running under 5.1 is using [machinename]/ASPNET user account by default. It's uncertain if speech server has issue to use this account to access local resource, but it definitively failed to use local windows account when accessing network resource under IIS 5.1. The error developer will see is like: Login failed for user ''. The user is not associated with a trusted SQL Server connection. Please note the user account here is a empty string.
Solution is to update to force impersonation in the machine.config under the currently used .NET framework folder. An example would be like this:
<processmodel password="[password]" username="[domain]\[username]">

here are some other good references helped me regarding this issue:
Understanding ASP.NET Impersonation Security
processModel Element (ASP.NET Settings Schema)

Wednesday, May 27, 2009

list<> sort or order using limbda expression

If doing an in-place sort (i.e. the list is updated):
people.Sort((x, y) => string.Compare(x.LastName, y.LastName));

If need to create a new list:
var newList = people.OrderBy(x=>x.LastName)

Springboard example, sorting sections on section No.

List
sections = new List
();
//... load sections ...
sections.Sort((x, y) => x.SectionNo.CompareTo(y.SectionNo));

insert from selecting from another database

In one case, I need to import data from one database to another database, and I've figured out the format should be

insert into server.newdatabase.owner.table
from select * from server.olddatabase.owner.table

the key point here is the four parts name follows the pattern server.database.owner.object