Joseph Michael Pesch
VP Programming

Forgot SQL Server Login

by 27. June 2011 08:52
On my current computer I had installed SQL Server 2008 locally some time back and forgot the "sa" password I had assigned at the time of installation and could not find it documented anywhere.  Also, it seems I did not add my windows account as an administrator as I could not login with integrated security even using the windows account that has local administrator access on the machine.  To solve this problem, I stopped the SQL service, added the "single user mode" parameter to the startup parameters, restarted the service, and changed the "sa" password using a SQL query window (SQL command shown below).
To add the "single user mode" startup parameter, open the "Sql Server Configuration Manager", right click on the "SQL Server (INSTANCENAMEHERE)" service and select "Properties", then click on the "Advanced" tab, scroll down to the "Startup Parameters" and add "-m;" (without the quotes) to the front of the existing parameters.
Restart the service, then through Sql Management Studio, open a new query window and change the connection string to your Sql Instance and run the following commands.  Note: You can put whatever new password you want in the @new parameter.  Once that is finished, go back and remove the "-m;" from the startup parameters, restart the service and login with your "sa" account and the new password you assigned.
exec sp_password @new='NewPasswordHere', @loginame='sa' 
go 
alter login sa 
enable 
go
Alternatively, if you cannot even login to the server, perform the following:
  1. Start the instance of SQL Server in single-user mode by using either the -m; or -f; options.
  2. Start command prompt as local administrator
  3. Connect to the server: sqlcmd -E -S SERVER_NAME_HERE
  4. Add yourself (computername\username) to the sysadmin SQL group with the following commands:
    • create login [computername\username] from windows;
    •  exec sp_addsrvrolemember 'computername\username', 'sysadmin';
  5. Restart the server in normal mode

Tags:

SQL Server

Get User that Initiated Task Change Event on a Workflow Task in Sharepoint

by 17. June 2011 11:13

This topic covers Sharepoint workflow tasks.  Specifically, the how to get the user account that triggered the workflow event.  By using the typical CurrentUser method on the Web object you will typically get the SHAREPOINT\system account rather than the actual account of the user that initiated the event.  Instead you can use the OriginatorUser method of the Workflowproperties as shown below.

// In both cases below you will typically get "SHAREPOINT\system"
Workflowproperties.web.CurrentUser;
// or
SPContext.Current.Web.CurrentUser;

// To get the acutal user that initiated task change event use this:
Workflowproperties.OriginatorUser

 

Tags:

C# | Sharepoint

Update Sharepoint Task Item inside Workflow Causes Item to be Indefinitely Locked by Workflow

by 17. June 2011 10:31

This topic covers updating a Sharepoint workflow task item, inside of a workflow event.  Sometimes performing an update to the item inside the workflow event will cause the item to be seen as indefinitely locked by the workflow in which case future attempts to update the same item (either inside a workflow event or by a user attempting to edi the item directly through the Sharepoint front end) will result in this error: "This task is currently locked by a running workflow and cannot be edited.". 

Typically, this will happen if you use the basic Update method of the item object (as shown in sample code below).  However, you should instead use the SystemUpdate method along with the explicit setting of the WorkflowVersion field value to 1 (as shown in sample code below).

/* You have to include the following two lines before the call to item.SystemUpdate()   
* to avoid this error:    
* "This task is currently locked by a running workflow and cannot be edited."   
* For details see:    
* http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.update%28v=office.12%29.aspx   
*/
web.AllowUnsafeUpdates = true; 
// You have to include this line  
item[SPBuiltInFieldId.WorkflowVersion] = 1;  
item.SystemUpdate(false);  // Don't use: item.Update(); 
//

Tags:

C# | Sharepoint

Sharepoint Hidden Site User List Collection

by 14. June 2011 10:48

Logged in as administrator, navigate to: _catalogs/users/simple.aspx

see: http://www.zimmergren.net/archive/2008/06/25/sharepoints-hidden-user-list-user-information-list.aspx

Tags:

Sharepoint

Sharepoint 2010 Get SPListItem with C# LINQ Syntax

by 14. June 2011 10:31

using (SPWeb web = new SPSite(workflowProperties.Web.Url).OpenWeb())

{

  SPListItem itm = (from x in web.Lists["List Name"].Items.OfType<SPListItem>()

                    where x["Field Name"] != null

                       && x["Field Name"].Equals("Value to search for")

                    select x).ToList<SPListItem>().FirstOrDefault();

}

Tags:

Deploy Visual Studio 2010 Sharepoint 2010 Workflow via .WSP File and STSADM

by 9. June 2011 10:04

NOTE:
Make sure the "Sharepoint 2010 Administration" service is NOT running.
Using execadmsvcjobs to execute in lieu of Timer service running them.
This ensures that the prior steps are complete before running the next.

Generate .WSP file by using the "Package" command from Visual Studio.

Copy .WSP file to somewhere on the Sharepoint server
for this example: "c:\MySpDeployment\MyWorkflow.wsp"
Run command window as Administrator and execute the commands below.

NOTE:
If you are re-installing the workflow you can first fully remove it
by using the Uninstall steps shown below the Install steps.

INSTALL STEPS

1) Navigate to the BIN where the STSADM.EXE exists
   (so we don't need the full path on all commands)

cd "c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"

2) Run all the STSADM commands...
stsadm -o addsolution -filename "MySpDeployment\MyWorkflow.wsp"
stsadm -o deploysolution -name "MyWorkflow.wsp" -immediate -allowgacdeployment -allowcaspolicies
stsadm -o execadmsvcjobs
stsadm -o activatefeature -name "MyWorkflow" -url http://yoursharepointsite

NOTE: 
Last step to activate feature requires exact folder name of feature.
Verify by navigating to the features folder to confirm the folder name.
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES

UNINSTALL STEPS

1) Navigate to the BIN where the STSADM.EXE exists
   (so we don't need the full path on all commands)

cd "c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"

NOTE: 
First step to deactivate feature requires exact folder name of feature.
Verify by navigating to the features folder to confirm the folder name.
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES

2) Run all the STSADM commands...
stsadm -o deactivatefeature -name "MyWorkflow" -url http://devuam
stsadm -o retractsolution -name "MyWorkflow.wsp" -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name "MyWorkflow.wsp"

Tags:

Sharepoint

Deploy Visual Studio 2010 Sharepoint 2010 Workflow via .WSP File and STSADM

by 9. June 2011 09:37

NOTE: Make sure the "Sharepoint 2010 Administration" service is NOT running.
      We are using the execadmsvcjobs to execute rather than letting th Timer service run them.

To install workflow from .WSP file ("Package" command from Visual Studio 2010 generates this file)
Copy the .WSP file to somewhere on the Sharepoint server (c:\MySpDeployment\MyWorkflow.wsp for this example)
Running command window as Administrator execute the commands below.
NOTE: If you are re-installing the workflow you can first fully remove it with the Uninstall steps also shown below.

INSTALL STEPS

1) Navigate to the BIN where the STSADM.EXE exists (so we don't need the full path on all commands)..
cd "c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"

2) Run all the STSADM commands...
stsadm -o addsolution -filename "MySpDeployment\MyWorkflow.wsp"
stsadm -o deploysolution -name "MyWorkflow.wsp" -immediate -allowgacdeployment -allowcaspolicies
stsadm -o execadmsvcjobs
stsadm -o activatefeature -name "MyWorkflow" -url http://devuam

NOTE: The last step to activate the feature requires the exact folder name where the feature was installed.
      You can verify by navigating to the features folder (listed below) and confirming the folder name.
      (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES

UNINSTALL STEPS

1) Navigate to the BIN where the STSADM.EXE exists (so we don't need the full path on all commands)..
cd "c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"

2) Run all the STSADM commands... (see NOTE from last step of install that also applies to first step of removal)
stsadm -o deactivatefeature -name "MyWorkflow" -url http://devuam
stsadm -o retractsolution -name "MyWorkflow.wsp" -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name "MyWorkflow.wsp"

Tags:

Sharepoint