Category : C#, VB.Net
Tags: iis

Cannot open database “” requested by the login. The login failed.
Login failed for user ‘IIS APPPOOL\DefaultAppPool’.
I got this error when I added an app onto IIS 7 and was trying to hit my local Database. Here is the fix:
1) In IIS7 – Click ‘Application Pools’ (left side)

—
2) On Top Right – Click ‘Set Application Pool defaults’

—
3) Finally, set ‘Process Model > Identity’ to ‘Local System’


$('#DIVID > div.CLASSNAME').each(function() {
numOfColumns++;
});
This asks for all divs within your holding div that have a certain class name. ** THE ‘ATGT’ after DIVID is a Greater Than sign**
You have a DIV and want to check if it is visible
Use the is() function passing “:visible” :
if( $('#myDiv').is(':visible') ) {}
Hidden
This is the same as checking if an element is visible but uses :hidden instead and the logic is the reverse:
if( $('#myDiv').is(':hidden') ) {}
Elements will return TRUE to the Hidden check even if they are not but take up no space!
Make the IS NOT check to combat this.
if( !$('#myDiv').is(':visible') {}
}
You can use the visible parameter to loop through all visible divs
$("#mydiv div:visible").each( function() {}
Had a div with a hidden input holding a value, wanted to get it… wanted a good way to select it… here is what I found.
$('input:hidden:first','#mydiv'); // get first one using first
$('input:hidden:last','#mydiv'); // get last one using last
$('input:hidden','#mydiv').eq(0); // get first one using eq
$('input:hidden','#mydiv').eq(1); // get second one using eq
$('input:hidden','#mydiv').eq(2); // get third one using eq
$('input:hidden:eq(0)','#mydiv'); // get first one using eq in selector
The options are:
first - get the first matched element in the collection.
last - get the last matched element in the collection.
eq(N) - get the Nth matched element, 0 based.
:eq(N) - get the Nth matched element, 0 based, inside the selector string.
However, using Hidden this way could also give you elements within your div that are NOT VISIBLE -- you could also use this;
$('input[type=hidden]', '#mydiv').eq(0);
Worked well for me, thanks StackOverflow!
Category : ADO / SQL, ASP.Net, C#
Tags: C#, SQL

THE KEY LINE BELOW IS : SqlCommandBuilder.DeriveParameters(cmd);
SqlConnection c = new SqlConnection(TextboxConnString.Text);
//NAME OF STORED PROC
string sql = DropdownStoredProcs.Value.ToString();
SqlCommand cmd = new SqlCommand(sql, c);
cmd.CommandType = CommandType.StoredProcedure;
c.Open();
SqlCommandBuilder.DeriveParameters(cmd);
foreach (SqlParameter param in cmd.Parameters)
{
if ((param.Direction == ParameterDirection.Input) || (param.Direction == ParameterDirection.InputOutput))
{
//Notice that I can get the Name of the parameter as well as it's DBType...
string paramDescription = param.ParameterName + " | " + param.SqlDbType.ToString();
DropdownSPParameters.Items.Add(paramDescription, param.ParameterName);
}
}
c.Close();
Category : ADO / SQL, C#
Tags: C#, SQL
This particular example fills a dropdown list with the list of Stored Procedures and takes it’s connection string from a textbox.
SqlConnection c = new SqlConnection(TextboxConnString.Text);
c.Open();
string sql = "SELECT name AS spname FROM sysobjects WHERE (xtype = 'p') ORDER BY name";
SqlCommand cmd = new SqlCommand(sql, c);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dtStoredProcs = new DataTable();
adapter.Fill(dtStoredProcs);
if (dtStoredProcs.Rows.Count > 0)
{
DropdownStoredProcs.Items.Clear();
foreach (DataRow dr in dtStoredProcs.Rows)
DropdownStoredProcs.Items.Add(dr["spname"].ToString(), dr["spname"]);
}
c.Close();
You can use JavaScript’s built-in parseInt() function to easily test for a numeric value:
if (myTextboxValue != parseInt(myTextboxValue))
alert(myTextboxValue + ' is not a whole number');
parseFloat will also allow you to get test if the data is a number (including floats)
It is easy to add one new control to your page but after that you may have troubles. Here is one option that uses Postbacks and Session.
Basically, I save a list of textboxes as a session variable and then check them on button click and add them to the form — I also give them unique ID’s so I can do something with them later on in the process…. Here is the code:
protected void Button1_Click(object sender, EventArgs e)
{
//This will be changed if we have controls in session.
int tbId = 1;
List seshTextboxes = new List();
if (Session["controlsList"] != null)
{
List list2 = (List)Session["controlsList"];
//Change the newest Id to the new tb
tbId = list2.Count + 1;
//Get controls out of session
foreach (ASPxTextBox tbSesh in list2)
{
seshTextboxes.Add(tbSesh);
form1.Controls.Add(tbSesh);
}
}
ASPxTextBox tb = new ASPxTextBox();
tb.ID = "Column" + tbId;
tb.Text = tbId.ToString();
seshTextboxes.Add(tb);
form1.Controls.Add(tb);
Session["controlsList"] = seshTextboxes;
}
Screenshot:

You can create any number of dynamic controls to your form this way.
SCENARIO:
Created a simple login that checked user name and password against a database and then sent user to the proper page if verified. (also writing a ‘logged in’ session variable)
Within the pages Page_Load event, I check for the proper session variable and if not present send them back to login screen.
Additionally, I added a logout link that wiped the variable and sent them back to login….
THING all appeared to work great… UNTIL I tried to navigate straight to a page AFTER logging out. The page was able to be accessed EVEN though I had logged out AND my Page_Load event was not even getting called.
====
REASON/SOLUTION:
The pages were being cached and therefore did not need to check the Page_Load event which would have caught the fact that the user was not properly logged in…. The solution is to place the following code in your Load event.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
** This is not a proper solution for a large solution with a lot of pages but for this purpose I only had one Default page with user controls … if you have many pages you should use the auth ticket option.
Believe it or not, you may come up against a situation where you do not whether a Javascript function exists in your page or not…. here is my scenario.
I am using usercontrols that are added to the page IF certain settings are set in the webconfig (something you might do if someone has one of your apps installed or has purchased a certain portions of your app) … so its possible this usercontrol has not been added to my page.
SO I need to know if I have a certain javascript function so that I can call it…. however if I call it or test for it WRONG I will get a Javascript error.
Here is the simple way to test this situation:
if(window.myJavascriptFunction) {
//do whatever I want to do now… like just CALL IT!
myJavascriptFunction();
}
hope this helps!
t