26 September 2016

..hold on to your Microsoft Excel TFS Team tab (TFS 2013, Excel 2013)

Problem

From TFS, I used the “Open Selection in Microsoft Excel” to create an Excel “report” that I can in future without having to open Visual Studio. My Work Item data is exported to Excel with the TEAM tab available, I then save and close the workbook.
When re-opening the workbook, my Work Item data is still there but no TEAM tab > no TFS connectivity > no “report” refresh. Must. Open. Visual Studio.

Solved

Solved by setting the Excel TFS add-in correctly, without manual update of the Registry keys.

In Excel,
1.     Navigate to File > Option > Add-Ins
2.      Select “COM Add-Ins” for the Manage drop-down list and click the “Go” button



3.     

































Select the two options and Click the “OK” button
a.     Team Foundation Add-in
b.     TFC  Office Shim



























   Reboot computer/laptop and open the Excel workbook. The TEAM tab is waiting already connecting to TFS.

Hope this helps you too..

24 August 2016

...CREATE/ALTER your procedure: 'CREATE/ALTER PROCEDURE' must be the first statement in a query batch

Problem

Creating or altering a stored procedure using dynamic SQL :

DECLARE @SQLCmd NVARCHAR(MAX)

SET @SQLCmd =
'IF OBJECT_ID(''[dbo].[StoredProcedureName]'') IS NOT NULL
    DROP PROCEDURE dbo.StoredProcedureName
GO
CREATE PROCEDURE [dbo].[StoredProcedureName]
AS
...'
EXEC(@SQLCmd)


Solved

Break the DROP and CREATE into 2 commands:

DECLARE @SQLCmd NVARCHAR(MAX)

SET @SQLCmd =
'IF OBJECT_ID(''[dbo].[StoredProcedureName]'') IS NOT NULL
    DROP PROCEDURE dbo.StoredProcedureName'
EXEC(@SQLCmd)

SET @SQLCmd =
'CREATE PROCEDURE [dbo].[StoredProcedureName]
 AS
 ...'
EXEC(@SQLCmd)


Or set only the CREATE command as dynamic code:

IF OBJECT_ID(''[dbo].[StoredProcedureName]'') IS NOT NULL
    DROP PROCEDURE dbo.StoredProcedureName
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

DECLARE @SQLCmd NVARCHAR(MAX)
SET @SQLCmd =
'CREATE PROCEDURE [dbo].[StoredProcedureName]
 AS
 ...'

EXEC(@SQLCmd)

Hope this helps..

27 August 2015

...retrieve your @Html.DropDownList selected value: the raison d'ĂȘtre for using a DropDownList

Problem

So I had a chance to dabble in jQuery and html, which I haven’t used in a minute but am familiar with. I came across the well documented challenge of returning the selected value for an html dropdown list back to a C# class.

Dropdown list data:

IList<SelectListItem> StuffList { get; set; }

...populate list then:

ViewBag.StuffSelection = StuffList;


html table element:

<td>
<label for="StuffSelector" style="font-size:16px">Select Stuff:</label>   
@Html.DropDownList("StuffSelection", (IEnumerable<SelectListItem>)ViewBag.StuffSelection")
</td>

 
jquery function:

$(function () {
$('#StuffSelection').change(function () {
document.location.href = '@Url.Action("StuffSelectionClass", "Home")' + '?SelectedStuff=' + $(this).find(":selected").text();
});


back in C#:

public ActionResult StuffSelectionClass (string SelectedStuff)
{
String retrievedValue = SelectedStuff;

       //then use the retrieved value for something or other
       ...
}

Solved

To give credit where it is due, this source is where I found help. The solution was adding an id for the dropdown list thus:

html table element:

<td>
<label for="StuffSelector" style="font-size:16px">Select Stuff:</label>   
@Html.DropDownList("StuffSelection", (IEnumerable<SelectListItem>)ViewBag.StuffSelection", new {@id="ddlStuffSelection"})
</td>

 
jquery function:

$(function () {
$('select#ddlStuffSelection').change(function () {
document.location.href = '@Url.Action("StuffSelectionClass", "Home")' + '?SelectedStuff=' + $(this).find(":selected").text();
});



Thank you source

22 July 2015

...find your ConfigurationManager: The type or namespace name 'ConfigurationManager' does not exist (huh?)

Problem

You’ve added the necessary using System.Configuration to your class yet the error persists:

The type or namespace name 'ConfigurationManager' does not exist blah blah in the namespace 'System.Configuration' (are you missing an assembly reference?)

So are you missing an assembly reference?

Yes. If you get the error, you are referencing the incorrect assembly.





























Solved

Load the correct version of the Assembly for your .NET Framework






















It’s that simple.

06 May 2015

…fix your parameter: because “The parameter is incorrect.” when updating registry key

Problem
The parameter is incorrect.
    at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
    at Microsoft.Win32.RegistryKey.CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, Object registrySecurityObj, RegistryOptions registryOptions)
    at Microsoft.Win32.RegistryKey.CreateSubKey

Solved
In my case user whose registry file I want to update (target user) is not logged in, therefore
..the user’s registry file is not loaded, therefore
…the registry path\key I’m pointing to is incorrect

My solution in a nutshell:
1.        Verify if the correct user id logged in (I could be lucky)

2.     Get the AccountID of current user logged in
      WindowsIdentity WId = WindowsIdentity.GetCurrent();
      WidAccountID = WId.User.ToString();

3.        Get the AccountID of the target user using NTAccount, SecurityIdentifier (see previous post)
      NTAccount NtAcct = new NTAccount(definedUserName);
      SecurityIdentifier SecId = SecurityIdentifier)NtAcct.Translate(typeof(SecurityIdentifier));
      SecAccountID = SecId.ToString();


4.        Compare the WidAccountID = SecAccountID
5.        If they are not equal, use RegLoadKey to load the target user’s registry hive file
6.        For above step, remember to prefix the registry sub key with registry hive alias

7.        If I’m lucky and target user is logged in, prefix registry sub key with AccountID

8.        Update the registry file
9.        Always close the registry key
10.     And if registry hive file was loaded, use RegUnLoadKey to unload

NOTE: I had a case where target user is not logged in but the hive file is loaded in registry, so my 3 checks are as follows:

1.   Target user logged in (WidAccountID = SecAccountID).
-        Set SecAccountID as registry path prefix.

2.   Target user not logged in but hive file loaded in registry. 
-        Set SecAccountID as registry path prefix.

3.   Target user not logged in, hive file not loaded in registry.
-        Load hive file and set hive alias as registry path prefix


This RegLoad help and many other sources tell you how to RegLoadKey and RegUnLoadKey