Friday, December 6, 2013

T-SQL: Silent Select

Here is the solution I found on SO in its simplest form:

SELECT SomeField
INTO #tmpDevNull
FROM some_table

This will store the selected result in a temporary table that will simply be disposed at the end of the request.

You might also want to begin with:

SET NOCOUNT ON

So no "rows affected" message is shown.

Thursday, October 17, 2013

Apache SetEnv does not work

Are you using it for a WSGI script? If so:

The SetEnv directive will not work as it only sets per request variables in WSGI environ dictionary and not process global os.environ.
Source

Well, this took me way too long to figure out. I was trying to use multiple environments for Trac and I was using its WSGI script. I just switched to the fcgi version and everything's fine now.

I'm off to bed. I'm so gonna hate my day tomorrow...

Thursday, September 5, 2013

Apache: couldn't perform authentication. authtype not set

I had this error in my /var/log/apache2/error.log file:

configuration error:  couldn't perform authentication. AuthType not set!: /~baldho/owncloud

Since the problematic path is a user directory, I added a Satisfy Any option to my Directory directive in my /etc/apache2/mods-enabled/userdir.conf file, like so:

<Directory /home/*/public_html>
    [...]
    Satisfy Any
    [...]
</Directory>


And the problem went away.

Apache: (403 Forbidden) in response to PROPFIND request

This error would be found in /var/log/apache2/error.log

If that happens in a user public_html, open the file /etc/apache2/mods-enabled/userdir.conf and make sure PROPFIND is included in the permissions:

<Limit GET POST OPTIONS PROPFIND MKCOL PUT>
    Order allow,deny
    Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND MKCOL PUT>
    Order deny,allow
    Deny from all
</LimitExcept>

The same Limit tag could be found or added in your /etc/apache2/sites-enabled/default file for a general effect.

This did the trick for me on my Debian system.

Wednesday, August 21, 2013

DevExpress MVC GridView - The inline edit form is not closed when the Update button is pressed

Various conditions can lead to this behavior. I found an interesting ticket about this on DevExpress website:


But that's not all: when the create/update callbacks are called onto the controller, if the method leaves with an invalid ModelState, the same thing occurs. In my case, this was be design and to fix it, I simply cleared the ModelState using ModelState.Clear().

One could also iterate through the ModelState to remove errors only. The goal here is to make the ModelState valid.

More info on this Stack Overflow question:

C# Get Localized Display Annotation without object instance

If you use an annotation on a model property like this:

[Display(ResourceType = typeof(MyLocalization.CommonModelsStrings), Name = "User_LastName")]
public string LastName { getset; }


Elsewhere you can access the localized display string of the model class without instantiating it using the following method. I put it in a static helper class named ModelAnnotationsUtils for easy access:

public static string GetLocalizedDisplay<TModel>(string pPropertyName)
{
 DisplayAttribute attribute = ((DisplayAttribute)(typeof(TModel).GetProperty(pPropertyName).GetCustomAttributes(typeof(DisplayAttribute), true)[0]));
 ResourceManager rm = new ResourceManager(attribute.ResourceType);
 return rm.GetString(attribute.Name);
}

Usage:

string lastName = ModelAnnotationsUtils.GetLocalizedDisplay<Model.User>("LastName");

Thursday, August 15, 2013

DevExpress MVC GridView: Allow empty string for empty textbox cell

I've been struggling for too long on this. I hope this helps a few.

Instead of writing the usual:

settings.Columns.Add("Name");

use this:

settings.Columns.Add(col =>
{
 col.FieldName = "Name";
 var tbxProperties = col.PropertiesEdit as TextBoxProperties;
 tbxProperties.ConvertEmptyStringToNull = false;
});

Not pretty, but does work.

Friday, August 9, 2013

ASP.Net MVC Html.ValidationMessageFor Static Layout

By default, the resulting field will not display if the validation is ok, and it'll appear when it's not. There might be a case where with such behavior, you end up with dynamically changing dimensions in your layout when editing the field under dynamic validation (jquery.validate.unobtrusive.js). The trick here is to make the hidden validation message occupy space. You can do this by adding this to your style sheet:

.field-validation-validspan.field-validation-error
{
 height: 13px;
 display: block;
}

You may change "display: block" to "display: inline-block" if you don't want the message to appear under the preceding element.

As of this writing, this is the only way I've been able to achieve this, as the ValidationMessageFor() method doesn't have any setting to play with. Suggestions are welcome!

Friday, August 2, 2013

ASP.Net Razor: jquery uncaught typeerror object has no method 'live'

This can happen if you'r using  jquery.unobtrusive-ajax with jQuery 1.9+.

jquery.unobtrusive-ajax uses old api methods that had the time to become deprecated and get entirely removed. As of this writing, JQuery is now 1.10.2 and jquery.unobtrusive-ajax still uses some removed methods.

My fix was pretty simple. Get https://github.com/jquery/jquery-migrate and include it after the jquery include line. The old methods (like live()) are now back.

<script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-migrate-1.2.1.min.js")" type="text/javascript"></script>

This should be only a temporary fix until MS gets in the real world and start using up to date APIs ;)

Hope this helps!