Login failed for user ‘username’. The user is not associated with a trusted SQL Server connection.

Comments Off

The cause of this problem is the SQL server has been configured to operate in “Windows Authentication Mode (Windows Authentication)” and doesn’t allow the use of SQL accounts. This was the default setting in my case, I got the error after installing a new instance of SQL Server 2005.

I was able to solve this problem by changing the Authentication Mode of the SQL server from “Windows Authentication Mode (Windows Authentication)” to “Mixed Mode (Windows Authentication and SQL Server Authentication)”.

HtmlMeta Class

Comments Off

private void AddMetaRefresh()
{
	HtmlMeta metaValue = null;

	metaValue = new HtmlMeta();
	metaValue.Attributes.Add("http-equiv", "refresh");
	metaValue.Attributes.Add("content", Settings.AutoRefreshInterval.ToString());

	this.Page.Header.Controls.Add(metaValue);
}

App_GlobalResources maps to a directory outside this application, which is not supported.

Comments Off

Problem

I’ve created a very simple ASP.NET 2.0 application. I can run this with no problems using the Built-in Web Server. However, if I publish it and try running the application by typing
http://localhost/talentdata/default.aspx directly in the browser window, I get the following error:
Server Error in ‘/talentdata’ Application.
The path ‘/talentdata/App_GlobalResources’ maps to a directory outside this application, which is not supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The path ‘/Beta2_TEST/App_GlobalResources’ maps to a directory outside this application, which is not supported.

Solution

The solution is quite simple. I checked the IIS Default Web Site Properties -> Home Directory -> Local Path. Don’t add any “\” character at the end of the directory, so I changed the Local Path to “C:\Inetpub\wwwroot” instead of “C:\Inetpub\wwwroot\” and restarted IIS.

IIS will automatically add one thus cause problem if you manually add one before. You can check Default Web Site Properties -> ASP.NET -> File Location for actual setting information.

Access Selected GridViewRow in GridView

Comments Off

GridViewRow selectedRow = (GridViewRow)(((Control)e.CommandSource).NamingContainer);

Gridview – Getting the RowIndex

Comments Off

The following syntax sets the rowindex equal to the specific row number:

int rowindex = ((GridViewRow)((Control)e.CommandSource).Parent.Parent).RowIndex;

How to access the EmptyDataTemplate controls from OnRowCommand in GridView

Comments Off

For example – inserting value in the empty gridview:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
 if (e.CommandName == "Insert") {
  TextBox txt  =
    (((Control)e.CommandSource).NamingContainer).FindControl("txtTest") as TextBox;

    //do insert action
 }
}

Another way to do this is by getting EmptyDataTemplate table and its controls:

if (e.CommandName == "Insert")

{
   Table table = (Table)GridView1.Controls[0];
   TextBox txtTest= (TextBox)table.Rows[0].FindControl("txtTest");

   //do insert actions
}

Error while trying to run project: Unable to start debugging on the web server

Comments Off

Open your Internet Information Services manager and from the [your machine]/Web Sites/ Default Web Site node select the virtual folder which stores your project. Right Click and select Properties to select the ASP.NET tab page. Make sure the correct version ASP.NET Version is selected.

I have VS.NET 2003 and 2005 beta 1 running side-by-side on my box and noticed ASP.NET Version 2.0 is targeted by default, even for VS.NET 2003 projects.

Change datagrid cell properties using ASP.NET C#

Comments Off

public void dgBoundItems(object sender, DataGridItemEventArgs e)
{
    foreach(TableCell cell in e.Item.Cells)
    {
        ///e.Item.DataSetIndex = row
        ///e.Item.Cells.GetCellIndex(cell) = column
        if (e.Item.Cells.GetCellIndex(cell) == 2 && e.Item.DataSetIndex > 0)
        {
            ///If the salary is less than 5000 the color must be red.
            if (Convert.ToInt32(cell.Text.Trim()) < 5000)
            {
                cell.ForeColor = Color.Red;
            }
        }
    }
}

Inline IF’ Statement

Comments Off

C#

string s;
s = (true ? "True" : "False"); //s will be "True"

VB.NET

Dim s As String
s = If(True, "True", "False") 's will be "True"
'In the following you cannot rely on a particular function
'not being called if the other argument is selected by Expression
'(notice IIf vs. If)
s = IIf(True, "True", "False") 's will be "True"

JavaScript

var s = (true) ? 'True' : 'False'; //s will be "True"

DateTime Format String

Comments Off

DateTime now = new DateTime(2006, 9, 07, 15, 06, 01, 08, DateTimeKind.Local);

now.ToString();      //"09/27/2006 15:06:01"

Year

now.ToString("%y");   //"6"

now.ToString("yy");   //"06"

now.ToString("yyy");  //"2006"

now.ToString("yyyy"); //"2006"

Month

now.ToString("%M");    //"9"

now.ToString("MM");    //"09"

now.ToString("MMM");   //"Sep"

now.ToString("MMMM");  //"September"

Day

now.ToString("%d");    //"7"

now.ToString("dd");    //"07"

now.ToString("ddd");   //"Thu"

now.ToString("dddd");  //"Thursday"

Hour

now.ToString("%h");    //"3"

now.ToString("hh");    //"03"

now.ToString("hhh");   //"03"

now.ToString("hhhh");  //"03"

now.ToString("%H");    //"15"

now.ToString("HH");    //"15"

now.ToString("HHH");   //"15"

now.ToString("HHHH");  //"15"

Minutes

now.ToString("%m");    //"3"

now.ToString("mm");    //"03"

now.ToString("mmm");   //"03"

now.ToString("mmmm");  //"03"

Seconds

now.ToString("%s");    //"1"

now.ToString("ss");    //"01"

now.ToString("sss");   //"01"

now.ToString("ssss");  //"01"

Milliseconds

now.ToString("%f");    //"0"

now.ToString("ff");    //"00"

now.ToString("fff");   //"008"

now.ToString("ffff");  //"0080"

now.ToString("%F");    //""

now.ToString("FF");    //""

now.ToString("FFF");   //"008"

now.ToString("FFFF");  //"008"

Kind

now.ToString("%K");    //"-07:00"

now.ToString("KK");    //"-07:00-07:00"

now.ToString("KKK");   //"-07:00-07:00-07:00"

now.ToString("KKKK");  //"-07:00-07:00-07:00-07:00"

(Source)

Older Entries Newer Entries