Thursday, December 28, 2006

char, varchar, nchar, nvarchar

nchar and nvarchar are used for unicode data, which require twice as much space (bytes) to store the same non-unicode characters. It is a significant disadvantage to use nchar and nvarchar if we do not need unicode charactors. Only use nchar & nvarchar when you need unicode charactors
use char & nchar when the length of the data is fixed, e.g. all customerID must be CUST_XXXX. use varchar and nvarchar when the length of the data is uncertain, e.g. customerID starts from 1 to 100000.

Monday, December 18, 2006

asp.net2.0 upload file

use FileUpload control. this example checks for file type, empty file

protected void btnSaveFile_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = @"C:\temp\";
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < fileextension ="="" fileok =" true;" text = "File uploaded!" text = "File could not be uploaded." text = "Cannot accept files of this type.">

reference: http://msdn2.microsoft.com/en-us/library/ms227669.aspx

Thursday, December 14, 2006

ASP.NET 2.0 “Ambiguous match found” error

when trying to load an ASPX page. The error was a “Parser Error” with “Ambiguous match found”.
The problem could be caused by having a member variable and a control variable with the same name (but different casing)
e.g.
private double aVariable = 0;
AnVariable.Text = aVariable .ToString("c");

The code will compile, and will run locally, but fails when deployed.

The solution is to rename the private member variables

*Thanks to Simon for the finding
*the reference: http://weblogs.asp.net/pjohnson/archive/2006/08/11/Ambiguous-match-found.aspx

Wednesday, December 06, 2006

unit testing issue (access denied - aborted) - VS Team - Developers

Symptom:
when i try to test a method, the result says "Aborted", and the error message was:
"Failed to Queue Test Run "@MACHINE1" 2006-12-04 17:13:30' with id {********-****-****-****-************}: Microsoft.VisualStudio.TestTools.TestManagement.ExecutionException: Test Run deployment issue: The location of the file or directory '\\server1\users\ab\my documents\visual studio 2005\projects\webservicepractice1\testproject1\bin\debug\testproject1.dll' is not trusted."

Solution
1. Control Panel --> .NET Framework 2.0 Configuration --> Runtime Security Policy --> Machine --> All_Code
2. Right click All_Code, select "New...", and give a name for your new group. Click Next and Next again
3. Type in "\\machine_name\shared_folder\assembly.dll" or "\\machine_name\shared_folder\*" and click Next
5. Make sure permission is set to FullTrust. Click Next, and Finish

.NET should be closed all the time while doing these settings