Wednesday 26 October 2011

Saturday 22 October 2011

How to disable the keyboard 'sleep' button on a windows PC

If you happen to own a keyboard with a sleep button in a terribly inconvenient location, such as next to a built-in keyboard volume control or next to your 'esc' key, occasionally causing you to accidentally put your PC to sleep, then there's hope. 


1). Go into power options in Windows Control Panel, (Start>Control Panel>Power Options)

 2). There should be an option on the left side menu to "Choose what the power buttons do". Clicking on that option will take you into System Settings, where you can 'define power buttons and turn on password protection'.


 3). Under "Power and sleep button settings", you can change the selected option for "When I press the sleep button:" in the drop down from 'Sleep' to 'Do nothing'


 4). Click 'Save changes', and Bob's your uncle! no restart necessary.


Wednesday 19 October 2011

Help with debugging JavaScript and/or identifying performance issues in IE

One of the improvements in IE 8 was the introduction of a JScript profiler which can provide useful JScript-related performance data during web development, and this feature has also been carried over into IE9.

To access the profiler, from IE9, launch the developer tools window either by selecting 'Tools>F12 developer tools' from the menu (shortcut keys: ALT+T,  L) or toggle on/off simply by pressing F12.

From the developer tools window, switch to the 'Profiler' tab, and then click 'Start profiling' to begin a profiling session. Click 'Stop profiling' to end the session. You can then view the resulting performance report in either 'Functions' view or 'Call tree' view, using the 'Current View' dropdown at the top of the window.

The developer window has a number of other handy features as well, such as disabling the pop-up blocker, disabling CSS, or validating HTML & CSS, etc.

More information can be found on the MSDN blog at: http://blogs.msdn.com/b/ie/archive/2008/09/11/introducing-the-ie8-developer-tools-jscript-profiler.aspx

Monday 10 October 2011

To configure Gmail on an Apple device (e.g. iPhone, iPad, iPod Touch), using Safari browser:

1. Make sure you've enabled 'IMAP' in your Gmail settings
2. Open the Settings app on your device
3. Tap Mail, Contacts, Calenders
4. Tap Add Account
5. Tap Gmail
6. Enter you account information, being sure to use your full Gmail address, uncluding @gmail.com
7. Tap Next
8. Tap Save

See full instructions on the Goggle Mail Help website, at : https://mail.google.com/support/bin/answer.py?answer=77702

Friday 7 October 2011

OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "Linked_Server_Name" returned message "Could not find installable ISAM.". Msg 7303, Level 16, State 1, Line 1 Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "Linked_Server_Name".

The knowledgebase at support.microsoft.com indicates this error can be the result of missing files or wrong filepaths in the Windows registry, etc. Check out suggested fixes here: http://support.microsoft.com/kb/283881/en-gb

However, I have also experienced that you will also get this error if your @provstr= for the Linked_Server_Name is set to "Excel 97 workbook" instead of "Excel 8.0"

For Example:

EXEC master.dbo.sp_addlinkedserver @server = N'Your_Linked_Server_Name', @srvproduct=N'Excel', @provider=N'Microsoft.Jet.OLEDB.4.0', @datasrc=N'C:\MortgagesDatabase\MortgageProduct.xls', @provstr=N'Excel 97 workbook'

instead of:

EXEC master.dbo.sp_addlinkedserver @server = N'Your_Linked_Server_Name', @srvproduct=N'Excel', @provider=N'Microsoft.Jet.OLEDB.4.0', @datasrc=N'C:\MortgagesDatabase\MortgageProduct.xls', @provstr=N'Excel 8.0'

Rounding decimal or floating point numbers in C#

Example from stackoverflow: http://stackoverflow.com/questions/257005/how-do-you-round-a-number-to-two-decimal-places-in-c


decimal a = 1.994444M;

Math.Round(a, 2); //returns 1.99

decimal b = 1.995555M;

Math.Round(b, 2); //returns 2.00


Math.Round also has an overload for rounding-to-even:

Math.Round(a, 2, MidPointRounding.ToEven);

Tuesday 4 October 2011

The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered.

Depending on your OS you could run odbcad32.exe on your SQL Server to bring up the Data Sources screen where you should be able to confirm what ODBC providers the server has installed (or not installed), as the case may be.


If you're using 64bit, then this error most likely results from the fact 64-bit SQL Server cannot use Jet, as there is no 64-bit OLEDB provider for Jet.


I came across a possible word-around, which could be to execute the following script in MSSMS, and then restart the MSSQLSERVER service:

EXEC

sp_configure 'show advanced options', 1;
GO

RECONFIGURE

;
GO

EXEC

sp_configure 'Ad Hoc Distributed Queries', 1
GO

RECONFIGURE

;
GO
Additional help can be found on this .Net forum: http://www.sqlservercentral.com/forums/Topic445277-149-1.aspx

Error 7399 When You Run a Linked Server Query That Uses the OLE DB Provider for Microsoft Jet


You may get the following errors when you run a query on a Linked Server that is configured to use OLEDB 4.0 provider for Microsoft Jet:

Error 7399: OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error.
[OLE/DB provider returned message: Unspecified error]
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IDBInitialize::Initialize returned 0x80004005: ].
OR
"Error 7399: OLE DB provider 'MSDASQL' reported an error. Driver's SQLSetConnectAttr failed The Microsoft jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data."


These problems probably occur because the login account does not have access to the temporary folder of the SQL Server startup account, because the linked server query runs in the context of the login account. If you run a linked server query, SQL Server tries to create a temporary file data source name (DSN) in the temporary folder of the SQL Server startup account.

To work around this problem, you could try the following:

1. Log on to the computer by using the SQL Server start up account.
2. Create a folder named Temp in the operating system installation directory.
3. Permit full access to a non-administrator account on the Temp folder.
4. Set the value of the TEMP and TMP user variables of the SQL Server startup account to the newly created Temp folder. To do so, follow these steps:
a. Right-click My Computer, and then click Properties.
b. Click the Advanced tab, and then click Environmental Variables.
c. In the User variables for Logon User list, click TEMP, and then click Edit.
d. In theVariable Value box, type C:\Temp as the location of the new Temp folder, and then click OK.
e. Repeat steps c and d to set the value of the TMP variable.
f. Click OK two times.

5. Log off, and then log on to the computer by using SQL Server startup account.
6. Restart the SQL Server services.


However, I've also experienced that you may get these errors if the datasource (i.e. the file path supplied in the @datasrc parameter of the sp_addlinkedserver query command) does not exist, or is missing. For example, if you forget to copy the file into the folder where the data source parameter of your linked server points to.


http://support.microsoft.com/kb/814398

Monday 26 September 2011

Removing Duplicate Rows from an Excel Spreadsheet

Microsoft has made this dead easy in MS Office 2010.
1. Open your spreadsheet to the worsksheet with duplicate rows
2. Switch to the 'Data' menu Ribbon
3. Click on 'Remove Duplicates'
4. This will open up a dialog where you can select the rows/columns with duplicates you want to remove.

Monday 19 September 2011

Date additions (T-SQL)

Adding number of x to a date, where x can be: year=yy, month=m, dayofyear=y, day=d, week=wk, hour=hh, minute=mi, second=ss.

For example adding 260 days to New Year's day 2011:

print dateadd(d, 260, '2011-01-01')

 
This should return Sep 18 2011



Calculate days since begninning of the Year (T-SQL)

print datediff(d, '2011-01-01', getdate())


Or get the difference between any two dates; format is datediff(d, ealier date, later date)
e.g
.



print datediff(d, '1969-07-20', '2011-09-19')

Monday 22 August 2011

“Network mapping is disabled by default on domain networks. Your network administrator can use Group Policy to enable mapping.”

FIX:
Open up a command prompt with elevated privileges:
From the elevated command prompt, run the command "gpedit.msc" (no quotes). This will start the group policy editor with Administrator privileges for the local machine.

Inside of the Group Policy Object Editor, navigate the tree to Local Computer Policy -> Computer Configuration -> Administrative Templates -> Network -> Link-Layer Topology Discovery.

Once you are in the Link-Layer Topology Discovery section of the editor, simply Right-click and open properties for "Turn on Mapper I/O (LLTDIO) driver" and set it to Enabled, and also tick the "Allow operation while in domain" option.


Network domain administrators who want to enable the Network Map across a group of machines should follow these same instructions and, additionally, link the policy to the desired Active Directory container.

Thursday 11 August 2011

System.Data.SqlClient.SqlException: Login failed for user '(username)'.


The first thing to check is whether the SQL Server is configured to use Mixed Mode Authentication or Integrated Authentication.

To do that, perform the following steps :-

1. Click Start - Programs - Microsoft SQL Server - Enterprise Manager to open the Enterprise Manager.
2. Connect to the appropriate Server if the SQL is a client installation.
3. Right click on the Server Node and click on Properties.
4. This opens the Properties Dialog.
5. Switch to the Security Tab.
6. Under the Security section, make sure the Option SQL Server and Windows is selected.
7. This ensures that your SQL Server is running under Mixed Mode Authentication.

The Next step is to ensure that the ASPNET account (IIS_WPG in case of Windows server 2003) has the appropriate access to the Database.

To do that, perform the following steps:

1. Open SQL Server Enterprise Manager (Start - Programs - Microsoft SQL Server - Enterprise Manager), select the appropriate server, and expand the Security folder.

2. In the Logins check whether the IIS_WPG is listed.
3. If it is not listed, right-click on Logins and select New Login
4. In the Name: textbox either enter [Server/Domain Name]\IIS_WPG or click on the ellipses button to open the Windows NT user/group picker.
5. Select the current machine’s IIS_WPG group and click Add and OK to close the picker. 
6. You then need to also set the default database and the permissions to access the database. To set the default database choose from the drop down list,
7. Next, click on the Database Access tab and specify the permissions.
8. Click on the Permit checkbox for every database that you wish to allow access to. You will also need to select database roles, checking db_owner will ensure your login has all necessary permissions to manage and use the selected database. 
9. Click OK to exit the property dialog. 

Your ASP.NET application is now configured to support integrated SQL Server authentication. 


http://www.eggheadcafe.com/community/aspnet/13/10190575/login-failed-for-user.aspx
.

CuteFTP 8.0 pro, Socket Error 10054

Fix: Check to make sure FTP Service is Started on the VPS Server. Then , for additional info see: http://kb.globalscape.com/KnowledgebaseArticle10235.aspx

Tuesday 9 August 2011

Sys.WebForms.PageRequestManagerServerErrorException: An unspecified error occurred.

You may experience this error if you're using an update Panel on an aspx page within an AJAX enabled web site.

This tutorial on the MSDN web site shows how to customize how the error is presented to the user and how to customize the error message: http://msdn.microsoft.com/en-us/library/bb398934.aspx

 In server code you can customize error handling by setting the AsyncPostBackErrorMessage property and handling the AsyncPostBackError event of the ScriptManager control. In client code you can customize error handing by handling the endRequest event of the PageRequestManager class.

You can add the following javascript immediately after your ScriptManager declaration to suppress this error:

   <script type="text/javascript" language="javascript">
   
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function
EndRequestHandler(sender, args) {
       
if (args.get_error() != undefined) {
           
var errorMessage;
           
if (args.get_response().get_statusCode() == '200') {
                errorMessage
= args.get_error().message;
           
}
           
else {              
               
// Error occurred somewhere other than the server page.
                errorMessage
= 'An unspecified error occurred. ';                                  
           
}
            args
.set_errorHandled(true);              
       
}
   
} </script>


See further details here: http://stackoverflow.com/questions/1271176/sys-webforms-pagerequestmanagerservererrorexception

Stop running this script? A script on this page is causing your browser to run slowly...


...If it continues to run, your computer might become unresponsive.


From a client perspective this may be prevented by doing the following:
·         Open Internet Explorer.
·         On the Tools menu, click Internet Options.
·         In the Internet Options dialog box, click Advanced.
·         Click to select the Disable script debugging check box.
·         Click to clear the Display a notification about every script error check box.
·         Click OK

For the intrepid techie, there is also a registry setting tweak you can attempt for overcoming this problem: See Miscorsoft support article here: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q175500

From a developer perspective check out this blog entry: http://www.picnet.com.au/blogs/Guido/post/2010/03/04/How-to-prevent-Stop-running-this-script-message-in-browsers.aspx

A further option for developers is using the IE8 Developer Tools JScript Profiler. Look this up on the MSDN blog here:
http://blogs.msdn.com/b/ie/archive/2008/09/11/introducing-the-ie8-developer-tools-jscript-profiler.aspx

Monday 8 August 2011

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level

Monday 1 August 2011

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

The reason that you may get this error message is the client stack could not receive SSRP response UDP packet from SQL Browser. The following steps may help to isolate the issue:

1) Make sure your server name is correct.
2) Make sure your instance name is correct and there is actually such an instance on your target machine. [Some application converts \\ to \. If you are not sure about your application, please try both Server\Instance and Server\\Instance in your connection string]
3) Make sure the server machine is reachable, e.g, DNS can be resolved correctly; you are able to ping the server.
4) Make sure SQL Browser service is running on the server.
5) If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.

Friday 29 July 2011

What is the sequence of events that happens when a client requests a .net apsx page?

User requests an application resource from the Web server:
The life cycle of an ASP.NET application starts with a request sent by a browser to the Web server (for ASP.NET applications, typically IIS). ASP.NET is an ISAPI extension under the Web server. When a Web server receives a request, it examines the file-name extension of the requested file, determines which ISAPI extension should handle the request, and then passes the request to the appropriate ISAPI extension. ASP.NET handles file name extensions that have been mapped to it, such as .aspx, .ascx, .ashx, and .asmx.


Note
If a file name extension has not been mapped to ASP.NET, ASP.NET will not receive the request. This is important to understand for applications that use ASP.NET authentication. For example, because .htm files are typically not mapped to ASP.NET, ASP.NET will not perform authentication or authorization checks on requests for .htm files. Therefore, even if a file contains only static content, if you want ASP.NET to check authentication, create the file using a file name extension mapped to ASP.NET, such as .aspx.



Note
If you create a custom handler to service a particular file name extension, you must map the extension to ASP.NET in IIS and also register the handler in your application's Web.config file


ASP.NET receives the first request for the application:

When ASP.NET receives the first request for any resource in an application, a class named ApplicationManager creates an application domain. Application domains provide isolation between applications for global variables and allow each application to be unloaded separately. Within an application domain, an instance of the class named HostingEnvironment is created, which provides access to information about the application such as the name of the folder where the application is stored.
The following diagram illustrates this relationship:
Application Topgraphy Overview Graphic
ASP.NET also compiles the top-level items in the application if required, including application code in the App_Code folder.



ASP.NET core objects are created for each request:
After the application domain has been created and the HostingEnvironment object instantiated, ASP.NET creates and initializes core objects such as HttpContext, HttpRequest, and HttpResponse. The HttpContext class contains objects that are specific to the current application request, such as the HttpRequest and HttpResponse objects. The HttpRequest object contains information about the current request, including cookies and browser information. The HttpResponse object contains the response that is sent to the client, including all rendered output and cookies.

An HttpApplicationobject is assigned to the request:
After all core application objects have been initialized, the application is started by creating an instance of the HttpApplication class. If the application has a Global.asax file, ASP.NET instead creates an instance of the Global.asax class that is derived from the HttpApplication class and uses the derived class to represent the application.


Note
The first time an ASP.NET page or process is requested in an application, a new instance of HttpApplication is created. However, to maximize performance, HttpApplication instances might be reused for multiple requests.


When an instance of HttpApplication is created, any configured modules are also created. For instance, if the application is configured to do so, ASP.NET creates a SessionStateModule module. After all configured modules are created, the HttpApplication class's Init method is called.


The following diagram illustrates this relationship:
Application Environment Graphic


The request is processed by theHttpApplicationpipeline:

The following events are executed by the HttpApplication class while the request is processed. The events are of particular interest to developers who want to extend the HttpApplication class.
  1. Validate the request, which examines the information sent by the browser and determines whether it contains potentially malicious markup. For more information, see ValidateRequest andScript Exploits Overview.
  2. Perform URL mapping, if any URLs have been configured in the UrlMappingsSection section of the Web.config file.
  3. Raise the BeginRequest event.
  4. Raise the AuthenticateRequest event.
  5. Raise the PostAuthenticateRequest event.
  6. Raise the AuthorizeRequest event.
  7. Raise the PostAuthorizeRequest event.
  8. Raise the ResolveRequestCache event.
  9. Raise the PostResolveRequestCache event.
  10. Based on the file name extension of the requested resource (mapped in the application's configuration file), select a class that implements IHttpHandler to process the request. If the request is for an object (page) derived from the Page class and the page needs to be compiled, ASP.NET compiles the page before creating an instance of it.
  11. Raise the PostMapRequestHandler event.
  12. Raise the AcquireRequestState event.
  13. Raise the PostAcquireRequestState event.
  14. Raise the PreRequestHandlerExecute event.
  15. Call the ProcessRequest method (or the asynchronous version IHttpAsyncHandler.BeginProcessRequest) of the appropriate IHttpHandler class for the request. For example, if the request is for a page, the current page instance handles the request.
  16. Raise the PostRequestHandlerExecute event.
  17. Raise the ReleaseRequestState event.
  18. Raise the PostReleaseRequestState event.
  19. Perform response filtering if the Filter property is defined.
  20. Raise the UpdateRequestCache event.
  21. Raise the PostUpdateRequestCache event.
  22. Raise the EndRequest event.
  23. Raise the PreSendRequestHeaders event.
  24. Raise the PreSendRequestContent event.

What is the key word you use in sql server stored procs to prevent locking?

WITH (NO LOCK)

What assembly do you reference for transaction processing on the .Net framework?

System.Transactions

Broken Function: There are some problems with the code below. Identify at least 4 issues.

private void GetCustomers()
{

System.Text.StringBuilder sBuilder = new System.Text.StringBuilder("");
System.Data.SqlClient.SqlDataReader oDR;
String sOutput;
System.Data.SqlClient.SqlConnection oConn;

try
{
System.Data.SqlClient.SqlCommand oCmd = new System.Data.SqlClient.SqlCommand("usp_GetCustomerNames",oConn);
                   
oCmd.CommandType = CommandType.StoredProcedure;
oDR = oCmd.ExecuteReader(CommandBehavior.CloseConnection);

while (oDR.Read)
{
sBuilder.Append(oDR("ForeName") & ";");
}
               
}
catch (Exception ex)
{

}

oDR.Close();

return sOutput;
}




ANS:


1) System.Data.SqlClient.SqlConnection oConn;
The connection object declared but then is not instantiated with a valid connection string,
for eample oConn.ConnectionString = “Data Source=(local);Database=AdventureWorks;Integrated Security=SSPI”


2)System.Text.StringBuilder("");
StringBuilder constructor arguments cannot be empty string

3) return sOutput;
No valid string is assigned to the sOutput variable returned by the GetCustomers() function.

4)
catch (Exception ex)
{

}
There is no code written to deal with the exception in the try/catch exception handler.
for example, to display a message to the user, or cancel the exception in order to allow processing to continue uninterruppted.

In CSS what would be the effects of and differences between the following:




1    #dvHeader UL LI A { color:red }
2    .dvHeader UL LI A { color:red }
3    #dvHeader A { color:red }
4    #dvHeader > A { color:red }


# is used as an id selector hence,
#dvHeader would match an Anchor elements in an un-numbered list's list Item, and of class dvHeader (className of dvHeader) [and set the InnerHTML (text ) contained within any one of these tags to the color red].

. is used for a style class definition hence,
.dvHeader would by used to assign the specified attributes (in this case the color red) to the Anchor element of a List Item of an un-numbered list
of class .dvHeader.

#dvHeader > A {color:red} would be used to match an anchor with the id value of #dvHeader and set its highlight color to red