A personal repository of technical notes. - CSC

Could not open a connection to SQL Server in ASP.NET on Windows 7 x64 IIS 7

Problem

While developing an ASP.NET website on a local Windows 7 x64 IIS 7 machine, received the following error:

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

However, a connection could be opened using SQL Server Management Studio (SSMS) with the same credentials used by the website.

Solution

Set up server alias in 64-bit version of SQL Native Client Configuration using Sql Server Configuration Manager. The reason that SSMS was working was because it was using the 32-bit aliases set up at an earlier time.

Missing System.Web.Extensions Reference in Windows 7 x64 VS2010

Problem

Unable to compile an ASP.NET 2.0 project in Visual Studio 2010 on Windows 7 x64 that references System.Web.Extensions (ASP.NET AJAX 1.0). The following errors were thrown:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "MyClass, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "MyClass, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3267: The primary reference "System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL".


Solution

1) Installed ASP.NET AJAX 1.0:

Download Details - Microsoft Download Center - ASP.NET AJAX 1.0
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=883

However, could not add a reference to System.Web.Extensions even though it was installed:


2) Had to manually add the following registry entry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx\ASP.NET AJAX Extensions]
@="C:\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET 2.0 AJAX Extensions\\v1.0.61025\\"


Could then add a reference to System.Web.Extensions:



References

"MSBUILD 4.0 Fails on AJAX Extensions." Visual Studio 2010 - MSBUILD 4.0 Fails on AJAX Extensions - Stack Overflow. 3 June 2010. Web. 26 July 2011.
<http://stackoverflow.com/questions/2966769/msbuild-4-0-fails-on-ajax-extensions>.

Windows SendTo Folder

Location (Windows 7)
C:\Users\MyUserName\AppData\Roaming\Microsoft\Windows\SendTo
or
%APPDATA%\Microsoft\Windows\SendTo
or
shell:sendto

Location (Windows XP)
C:\Documents and Settings\MyUserName\SendTo
or
%USERPROFILE%\SendTo
or
shell:sendto

Tip to Open SendTo Folder (Windows 7, XP)
1) Create a text file in SendTo folder called "Open SendTo Folder.bat".
2) Add the following line:
start explorer.exe shell:SendTo
3) To quickly open SendTo folder while using the right-click/Send to feature, click on "Open SendTo Folder.bat".

Team Foundation Server Compare Ignore Whitespace

Problem

Need to get TFS Compare to ignore whitespace

Solution

Select menu item Tools/Options/Visual Studio Team Foundation Server.
Click button Configure User Tools...
Click Add
Extension = .*
Operation = Compare
Command = C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\diffmerge.exe
Arguments = %1 %2 %6 %7 %5 /ignorespace

See command line help with:
"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\diffmerge.exe" /?

References

"JB Brown: Whitespace in Team System Compare Results - TeamReview, Visual Studio Team System, and Lean." JB Brown - TeamReview, Visual Studio Team System, and Lean. Web. 21 June 2011.
<http://www.controlstatements.com/2009/03/whitesapce-in-team-system-compare.html>.

"Difference Command." MSDN Explore Desktop, Web, Cloud, and Phone Software Development. Web. 21 June 2011.
<http://msdn.microsoft.com/en-us/library/6fd7dc73(VS.80).aspx>.

How to Install Microsoft Free Virus Software

  1. Download Microsoft Security Essentials installation file to your desktop
    Virus, Spyware & Malware Protection | Microsoft Security Essentials
    http://www.microsoft.com/en-us/security_essentials/default.aspx
  2. Disconnect from the internet because you will be unprotected for a few minutes. Unplug from the cable modem, etc.
  3. Uninstall virus/security software that is currently on your computer.
    If you need help figuring out how to uninstall, connect back up to the internet, go to this page and print it off, then disonnect again:
    How do I uninstall antivirus or antispyware programs?
    http://www.microsoft.com/en-us/security_essentials/Support/4cae1455-6ead-493c-b5d8-7c88f39c0656.aspx
  4. Install Microsoft Security Essentials from your desktop installation file.
  5. Make sure Windows firewall is turned on in case the old security software included a firewall.
    Understanding Windows Firewall settings
    http://windows.microsoft.com/en-US/windows7/Understanding-Windows-Firewall-settings
  6. Reconnect to the internet and allow Microsoft Security Essentials to update itself.

SQL Concatenate Row Data into Variable

Problem

Need to generate a comma-delimited string list from data contained in rows of table

Solution

DECLARE @commaDelimitedList varchar(8000)
SET @commaDelimitedList = '' -- Must set to empty value

SELECT @commaDelimitedList = @commaDelimitedList + [MyColumn] + ','
FROM [MyTable]

-- Remove trailing comma from list
IF (@commaDelimitedList <> '')
BEGIN
      SET @commaDelimitedList = LEFT(@commaDelimitedList, LEN(@commaDelimitedList) - 1)
END

-- Return record set
SELECT @commaDelimitedList AS 'CommaDelimitedList'

Debug Console Application When Started Outside of Visual Studio

Problem

Need to be able to debug a console application when the executable is started outside of Visual Studio. When doing this with a web application, you attach to process aspnet_wp.exe. This will not work with a console application.

Solution

Manually start debugger inside console application. Temporarily add the following line to the console application code:

System.Diagnostics.Debugger.Launch();

Running the console application executable will cause a prompt from Visual Studio Just-In-Time Debugger. At that time you may select Visual Studio from list of Possible Debuggers.

Option Strict On disallows late binding

Problem

When setting Option Strict On in Visual Studio macro, the following code examples:

Dim toolbar As Microsoft.VisualStudio.CommandBars.CommandBar
toolbar = DTE.CommandBars.Item("MyToolbarName")
DTE.ActiveDocument.Selection.NewLine()


Causes the error:

Option Strict On disallows late binding.

Solution

Use CType Function to explicitly convert an expression to a specified object like the following examples:

toolbar = CType(DTE.Commands.Item("MyToolbarName"), Microsoft.VisualStudio.CommandBars.CommandBar)
Dim activeDocument As Document = CType(DTE.ActiveDocument, Document)
Dim activeSelection As TextSelection = CType(DTE.ActiveDocument.Selection, TextSelection)

Windows XP Hangs Viewing Shortcuts

Problem
Windows hangs when opening or trying to view properties of shortcuts to network files that do not exist.

Note: This solution has been tested and works with Windows XP and Windows 7.

Solution
Prevent Windows from conducting a comprehensive search of the target drive in an attempt to find the file.
  1. Run gpedit.msc
  2. Select User Configuration / Administrative Templates / Start Menu and Taskbar
  3. Enable "Do not use the search-based method when resolving shell shortcuts"
References
"Windows XP Hangs When You Open a Folder That Contains a Network Shortc." PC Pitstop Forums. Web. 04 Mar. 2011.
<http://forums.pcpitstop.com/index.php?/topic/121312-windows-xp-hangs-when-you-open-a-folder-that-contains-a-network-shortc/>.
"Policy Settings for the Start Menu in Windows XP." Microsoft Support. Web. 04 Mar. 2011.
<http://support.microsoft.com/kb/292504>.
"Do Not Use the Search-based Method When Resolving Shell Shortcuts." Microsoft TechNet: Resources for IT Professionals. Web. 04 Mar. 2011.
<http://technet.microsoft.com/en-us/library/cc939469.aspx>.

Updates
2011-10-20 Added note that this works with XP and Win7.

KB2418241 MS10-070 Breaks Forms Authentication Ticket Sharing Between v1.1 and v2.0

Problem
Shared forms authentication between ASP.NET 1.1 and 2.0 stopped working after installing Security Update for Microsoft .NET Framework 2.0 SP2 and 3.5 SP1 on Windows Server 2003 and Windows XP x86 (KB2418241).

Received the following error in Application Event Viewer after authenticating in a v1.1 web page and then browsing to a v2.0 web page:
Event code: 4005
Event message: Forms authentication failed for the request. Reason: The ticket supplied was invalid.

Solution
As of 11/1/2010: Apply Hotfix KB2433751.

"KB2433751 - Form Authentication Ticket Compatibility Issue with MS10-070 - Home." MSDN Code Gallery - Home. Web. 01 Nov. 2010.
<http://code.msdn.microsoft.com/KB2433751>.

Note: Download NDP1.1sp1-KB2433751-X86.exe worked with Windows XP.

References
"MS10-070: Description of the Security Update for the Microsoft .NET Framework 3.5 Service Pack 1 and .NET Framework 2.0 Service Pack 2 on Windows Server 2003 and on Windows XP." Microsoft Support. Web. 01 Nov. 2010.
<http://support.microsoft.com/kb/2418241>.

"FIX: Forms Authentication Cookies Compatibility Issue between .NET Framework 1.1 and .NET Framework 2.0 SP2 ASP.NET Applications after You Apply the Security Update from Security Bulletin MS10-070." Microsoft Support. Web. 01 Nov. 2010.
<http://support.microsoft.com/kb/2433751>.

"KB2433751 - Form Authentication Ticket Compatibility Issue with MS10-070 - Home." MSDN Code Gallery - Home. Web. 01 Nov. 2010.
<http://code.msdn.microsoft.com/KB2433751>.

"Legacy Encryption Mode and Microsoft .NET Framework 1.1 - ASP.NET Forums." Forums.asp.net : The Official Microsoft ASP.NET Forums. Web. 01 Nov. 2010.
<http://forums.asp.net/t/1609592.aspx>.