Joseph Michael Pesch
VP Programming

SQL Server Drop Extended Properties (e.g. MS_Description)

by 8. September 2015 04:38

This script will generate a set of drop statements:

--tables
 select 'EXEC sp_dropextendedproperty
 @name = '''+name+'''
 ,@level0type = ''schema''
 ,@level0name = ' + object_schema_name(extended_properties.major_id) + '
 ,@level1type = ''table''
 ,@level1name = ' + object_name(extended_properties.major_id)
 from sys.extended_properties
 where extended_properties.class_desc = 'OBJECT_OR_COLUMN'
 and extended_properties.minor_id = 0
 union
 --columns
 select 'EXEC sp_dropextendedproperty
 @name = '''+sys.extended_properties.name+'''
 ,@level0type = ''schema''
 ,@level0name = ' + object_schema_name(extended_properties.major_id) + '
 ,@level1type = ''table''
 ,@level1name = ' + object_name(extended_properties.major_id) + '
 ,@level2type = ''column''
 ,@level2name = ' + columns.name
 from sys.extended_properties
 join sys.columns
 on columns.object_id = extended_properties.major_id
 and columns.column_id = extended_properties.minor_id
 where extended_properties.class_desc = 'OBJECT_OR_COLUMN'
 and extended_properties.minor_id > 0

Tags:

SQL Server

BundleConfig EnableOptimizations Breaks Font Awesome

by 30. August 2015 15:13

When using Font Awesome with bundling and optimization you need to add the CssRewriteUrlTransform() to the font awesome bundle (as shown below).

BundleTable.EnableOptimizations = true;

bundles.Add(new StyleBundle("~/bundles/css/font-awesome").Include(
  "~/css/font-awesome.min.css", new CssRewriteUrlTransform()
));

Tags:

CSS

Bootstrap Image Slider Center Image

by 30. August 2015 12:03

div.carousel-wrapper{
    width: 80%; /* for example */
    margin: auto;
}

.carousel-inner > .item > img,
.carousel-inner > .item > a > img{
width: 100%; /* use this, or not */
margin: auto;
}

Tags:

CSS

Bootstrap Image Slider Center Image

by 30. August 2015 12:03

div.carousel-wrapper{
    width: 80%; /* for example */
    margin: auto;
}

.carousel-inner > .item > img,
.carousel-inner > .item > a > img{
width: 100%; /* use this, or not */
margin: auto;
}

Tags:

CSS | Bootstrap

SQL Server TSQL DateDiff Between Weekdays Only

by 20. August 2015 07:04

declare @d1 datetime, @d2 datetime
select @d1 = '8/1/2015',  @d2 = '8/20/2015'

select datediff(dd, @d1, @d2) - (datediff(wk, @d1, @d2) * 2) -
       case when datepart(dw, @d1) = 1 then 1 else 0 end +
      case when datepart(dw, @d2) = 1 then 1 else 0 end

Tags:

SQL Server

Remove hiberfile.sys from Windows C: Drive

by 2. August 2015 09:46

Run CMD as administrator and run the following commands:

POWERCFG -X -hibernate-timeout-dc 0
POWERCFG -X -hibernate-timeout-ac 0
POWERCFG -H OFF

Tags:

iPhone Backup File Locations

by 26. July 2015 14:58

When iTunes backs up your iPhone, iPad or iPod Touch, it saves all your important data into various files within the backup folder.

The filenames are encoded so they appear as strings of letters and numbers. It turns out, however, that for each version of the iPhone operating system (iOS), they're encoded in similar ways.

Here are some of the main files.

iOS 6 iPhone Backup File Locations

ContentsReal FilenameFilename in Backup
SMS sms.db 3d0d7e5fb2ce288813306e4d4636395e047a3d28
Contacts AddressBook.sqlitedb 31bb7ba8914766d4ba40d6dfb6113c8b614be442
Calendar Calendar.sqlitedb 2041457d5fe04d39d0ab481178355df6781e6858
Reminders Calendar.sqlitedb 2041457d5fe04d39d0ab481178355df6781e6858
Notes notes.sqlite ca3bc056d4da0bbf88b5fb3be254f3b7147e639c
Call hist. call_history.db 2b2b0084a1bc3a5ac8c27afdf14afb42c61a19ca
Locations consolidated.db Removed from iTunes backup, not iDevice

iOS 5 iPhone Backup File Locations

ContentsReal FilenameFilename in Backup
SMS sms.db 3d0d7e5fb2ce288813306e4d4636395e047a3d28
Contacts AddressBook.sqlitedb 31bb7ba8914766d4ba40d6dfb6113c8b614be442
Calendar Calendar.sqlitedb 2041457d5fe04d39d0ab481178355df6781e6858
Reminders Calendar.sqlitedb 2041457d5fe04d39d0ab481178355df6781e6858
Notes notes.sqlite ca3bc056d4da0bbf88b5fb3be254f3b7147e639c
Call hist. call_history.db 2b2b0084a1bc3a5ac8c27afdf14afb42c61a19ca
Locations consolidated.db Removed from iTunes backup, not iDevice

iOS 4 iPhone Backups

ContentsReal FilenameFilename in Backup
SMS sms.db 3d0d7e5fb2ce288813306e4d4636395e047a3d28
Contacts AddressBook.sqlitedb 31bb7ba8914766d4ba40d6dfb6113c8b614be442
Calendar Calendar.sqlitedb 2041457d5fe04d39d0ab481178355df6781e6858
Notes notes.sqlite ca3bc056d4da0bbf88b5fb3be254f3b7147e639c
Call hist. call_history.db 2b2b0084a1bc3a5ac8c27afdf14afb42c61a19ca
Locations consolidated.db 4096c9ec676f2847dc283405900e284a7c815836

iOS 3 iPhone Backups

ContentsReal FilenameFilename in Backup
SMS sms.db 3d0d7e5fb2ce288813306e4d4636395e047a3d28
Contacts AddressBook.sqlitedb 31bb7ba8914766d4ba40d6dfb6113c8b614be442
Calendar Calendar.sqlitedb 2041457d5fe04d39d0ab481178355df6781e6858
Notes notes.db 740b7eaf93d6ea5d305e88bb349c8e9643f48c3b
Call hist. call_history.db ff1324e6b949111b2fb449ecddb50c89c3699a78

iOS 2 iPhone Backups

ContentsReal FilenameFilename in Backup
SMS sms.db 3d0d7e5fb2ce288813306e4d4636395e047a3d28
Contacts AddressBook.sqlitedb 31bb7ba8914766d4ba40d6dfb6113c8b614be442
Calendar Calendar.sqlitedb 2041457d5fe04d39d0ab481178355df6781e6858
Notes notes.db 740b7eaf93d6ea5d305e88bb349c8e9643f48c3b
Call hist. call_history.db ff1324e6b949111b2fb449ecddb50c89c3699a78

iOS 1 iPhone Backups

ContentsReal FilenameFilename in Backup
SMS sms.db 3d0d7e5fb2ce288813306e4d4636395e047a3d28
Contacts AddressBook.sqlitedb adb8c77534444e97c31ff15924d50f3ed1fbd3b1
Calendar Calendar.sqlitedb 14ee8cdc3e6e0220399ff210246e1c92b7df89a0
Notes notes.db 740b7eaf93d6ea5d305e88bb349c8e9643f48c3b
Call hist. call_history.db a49bfab36504be1bf563c1d1813b05efd6076717

From: http://www.iphonebackupextractor.com/blog/2012/apr/23/what-are-all-files-iphone-backup/

 

Tags:

Bitnami Wordpress How To Remove the Manage Banner

by 7. June 2015 20:58


How to remove the banner

In case you wan't to remove the banner, you will just need to SSH into your machine and then execute the following command:

sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1
Please note the actual path will depend on the installed application so it may be different in your case (/opt/bitnami/apps/drupal/bnconfig for Drupal, /opt/bitnami/apps/joomla/bnconfig for Joomla...).

And then restart Apache:

sudo  /opt/bitnami/ctlscript.sh restart apache

Please note the above steps will only remove the corner banner, the Bitnami info page will still be availble by visiting  http://example.com/bitnami/index.html

Original source: https://wiki.bitnami.com/Components/Bitnami_info_page

Tags:

Piranha CMS Uses TinyMCE and Removes Certain Tags Like FontAwesome <i> Tags

by 9. May 2015 10:27

I was using Piranha CMS with the out-of-the-box implementation in conjunction with an MVC Bootstrap HTML/CSS template.  This was working great with the exception of certain tags (specifically in my case the <i> tag used in conjunction with FontAwesome) would get removed.  This is because by default the TinyMCE html editor that Piranha CMS uses will only retain the configured allowable tags.  I fixed this issue by adding my <i> tag to the configuration of allowable tags using the "extended_valid_elements" configuration setting of TinyMCE.  This setting adds additional allowed tags/attributes in the TinyMCE editor in addition to the default allowed tags/attributes. 

In my case the specific setting looked like this: extended_valid_elements : 'i[*]'

In order to implement this with Piranha CMS I needed to add a new file "TinyMCE.cshtml" to the folder "Areas\Manager\Views\Shared\Partial" in my MVC project (side note, that full folder path did not already exist so I added the necessary sub-folders).  Here is the full content of the TinyMCE.cshtml file:

<script type="text/javascript" src="~/res.ashx/areas/manager/content/js/ext/tiny_mce/tinymce.min.js"></script>
<script type="text/javascript">
  tinymce.init({
    extended_valid_elements : 'i[*]',
    mode: 'specific_textareas',
    editor_selector: "editor",
    convert_urls: false,
    plugins: [
        "autoresize autolink code hr paste piranhaimage link"
    ],
    width: "100%",
    height: "340",
    autoresize_min_height: 340,
    @if (File.Exists(Server.MapPath("~/areas/manager/content/css/editor.css"))) {
        <text>content_css: "@Url.Content("~/areas/manager/content/css/editor.css")",</text>
        }
    toolbar: "bold italic underline | bullist numlist hr | formatselect removeformat | cut copy paste | link piranhaimage | code",
  });
</script>

Tags:

ASP.Net | MVC

TSQL Function to Return Number of Weekdays Between Two Dates (Excludes Weekend Days)

by 4. May 2015 10:41

TSQL function to return a number of weekdays between two dates (i.e. excludes weekend days):

create function WeekdayDateDiff
(
 @BegDt as DATETIME,
 @EndDt as DATETIME
) returns int as begin
  return (datediff(dd, @BegDt, @EndDt) + 1)
  -(datediff(wk, @BegDt, @EndDt) * 2)
  -(case when datepart(dw, @BegDt) = 1 then 1 else 0 end)
  -(case when datepart(dw, @EndDt) = 7 then 1 else 0 end)
end

Tags:

SQL Server

SharePoint PowerPivot Data Refresh - Can't Open the Workbook Because it Uses Unsupported Features

by 14. April 2015 07:44

Trying to run the SharePoint PowerPivot Unattended Data Refresh errors with: "We're sorry. We can't open the workbook in the browser because it uses these unsupported features: • Comments, Shapes, or other objects"

Use this tool from: http://blogs.msdn.com/b/cumgranosalis/archive/2007/06/29/excel-services-compatibility-checker-download-page.aspx

to fix the workbook.

Tags:

Sharepoint

IIS Application Pool (AppPool) Using Default Identity of "ApplicationPoolIdentity"

by 10. March 2015 04:46

To assign Windows security (for example local folder permissions) to the ApplicationPoolIdentity user there is a user for each website like this: IIS APPPOOL\website

 


Tags:

Installing and Configuring Web Deploy on IIS 8.0 or Later

by 10. March 2015 04:37

 

1) Install the "Web Platform Installer" (version 4.6 at time of this post).

2) Use the "Web Platform Installer"to install the "Recommended Server Configuration for Web Hosting Providers" (search for "recommended" should locate this item).

 

See full blog post here: http://www.iis.net/learn/install/installing-publishing-technologies/installing-and-configuring-web-deploy-on-iis-80-or-later

 


Tags:

Microsoft SQL Server TSQL Script to View All User Role Assignments

by 10. March 2015 04:01

 

/* The following will list all user role assignments in current database */


WITH RoleMembers (member_principal_id, role_principal_id)
AS
(
  SELECT
   rm1.member_principal_id,
   rm1.role_principal_id
  FROM sys.database_role_members rm1 (NOLOCK)
   UNION ALL
  SELECT
   d.member_principal_id,
   rm.role_principal_id
  FROM sys.database_role_members rm (NOLOCK)
   INNER JOIN RoleMembers AS d
   ON rm.member_principal_id = d.role_principal_id
)
select distinct rp.name as database_role, mp.name as database_user
from RoleMembers drm
  join sys.database_principals rp on (drm.role_principal_id = rp.principal_id)
  join sys.database_principals mp on (drm.member_principal_id = mp.principal_id)
order by rp.name

/* The following will list all user role assignments in all databases except master and tempdb */

create table #tmp(DatabaseName varchar(150), DatabaseRole varchar(150), DatabaseUser varchar(150))

declare @command varchar(max)

select @command = '
if ''?'' not in(''master'', ''tempdb'')
begin
    print ''?''
    use [?]
  ;
  WITH RoleMembers (member_principal_id, role_principal_id)
  AS
  (
    SELECT
     rm1.member_principal_id,
     rm1.role_principal_id
    FROM sys.database_role_members rm1 (NOLOCK)
     UNION ALL
    SELECT
     d.member_principal_id,
     rm.role_principal_id
    FROM sys.database_role_members rm (NOLOCK)
     INNER JOIN RoleMembers AS d
     ON rm.member_principal_id = d.role_principal_id
  )
  insert into #tmp select distinct ''?'', rp.name, mp.name
  from RoleMembers drm
    join sys.database_principals rp on (drm.role_principal_id = rp.principal_id)
    join sys.database_principals mp on (drm.member_principal_id = mp.principal_id)
  order by rp.name

end
'
exec sp_msforeachdb @command1 = @command

select * from #tmp

drop table #tmp

Tags:

SQL Server

ASP.Net Visual Studio General XML Configuration File Transformation

by 3. March 2015 05:19

Slow Cheetah is a Visual Studio addin (VSIX Installer available here: https://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5) that enables build specific transformations for any XML configuration file (similar to the out of the box Visual Studio support for Web.config transformation files).  Here is a blog from Scott Hanselman talking about the tool: http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx

 

Tags:

Piranha CMS for MVC Installation

by 22. February 2015 05:44

When I first installed Prianha CMS for MVC I was having issues running it.  I started over and installed via NuGet package manager console in the following order:

PM > Install-Package PiranhaCMS.Core

PM > Install-Package PiranhaCMS.WebPages

PM > Install-Package PiranhaCMS.MVC

PM > Install-Package PiranhaCMSMVC

 

Tags:

C# | MVC

Convert Standard MVC Website to SPA (Single Page Application) Using Sammy.js

by 19. February 2015 07:17

Step One: The Layout Page

For MVC the layout page is a template that ASP.NET uses to render a single HTML document by merging it with the markup in a view page.  In a SPA, the Layout becomes a shell page into which the view's markup is loaded via AJAX calls. The Layout page's lifespan is now the user's session, rather than just the lifespan of the page, so be careful what you scope at this level; the safety net of a page refresh that cleans up after us is gone, and browser memory leaks are distinctly counter-excellent in nature.

To convert a standard MVC website to SPA we'll use NuGet to add Sammy.js to our project. Sammy (among other things) is a jQuery-dependent JavaScript framework which lets us add URL routing to the client side of our app.

Once we've brought in Sammy, we'll add it to a bundle (along with jQuery) in BundleConfig.RegisterBundles:

bundles.Add(new ScriptBundle("~/js/mvc-spa").Include(
    "~/Scripts/jquery-{version}.js",
    "~/Scripts/sammy-{version}.js"));

Then we'll render the bundle at the bottom of our Layout page:

            @Scripts.Render("~/js/mvc-spa")
    </body>
</html>

We'll also need to designate the area of the Layout where the view content will be loaded by finding the element we are currently calling RenderBody and giving it a unique id. For this example, let's go with "page".

<!-- ... -->
</header>
<section id="page">
	@RenderBody()
</section>
<footer>
<!-- ... -->    

Step Two: Go Partial

Next, we need to go through our views, and, with the exception of the Home/Index view, convert each to a Partial View.

Unlike vanilla MVC Views, Partial Views are not merged with the Layout page to render as complete HTML documents. When you make a controller request that returns a Partial View, the response is merely an HTML fragment–precisely what we're looking for in a SPA page.

To convert a View to a Partial, simply change the View call to a call to PartialView in its corresponding Controller Action:

public class SpaFtwController : Controller {
    public ActionResult Index() {
        return PartialView();
    }
}

As I may have mentioned above, do not convert your default view to a partial. This view is the "single page" in "single-page application", and it still needs to render as a complete HTML document, just the once. However, we should move this Index view's content into a separate Partial View, and replace it with some sort of splash content that will only display while our app is still loading. More on that in the next step.

Step Three: One Route to rule them all

The typical usage of Sammy is to describe multiple hash-based routes, along with the js to be executed when the user navigates to them. What we're going to do in this case, though, is create a solitary Sammy route that acts as a pass-through to the existing MVC routing already in place on the server-side.

For example, a request to /#/spaftw would load the content from /SpaFTW into our app. Using fragment identifiers for routing is a classic SPA technique; it changes the browser's URL without causing a whole page request, while also allowing the back button to still work as expected, and enables deep-linking into the app.

Here is a module that contains the code to do just this. We'll add it to our project in a file named Routing.js.

var Routing = function (appRoot, contentSelector, defaultRoute) {
function getUrlFromHash(hash) { var url = hash.replace('#/', ''); if (url === appRoot) url = defaultRoute; return url; }
return { init: function () { Sammy(contentSelector, function () { this.get(/\#\/(.*)/, function (context) { var url = getUrlFromHash(context.path); context.load(url).swap(); }); }).run('#/'); } }; }

Let's unpack that. See the this.get call about two-thirds of the way down? That's Sammy's bread and butter. We're using a regular expression to describe a route URL that captures any href beginning with '/#'. When a request is made for a URL matching this expression, Sammy intercepts it and runs the function that we've passed as get's second parameter. This function grabs this path, strips out the hash, makes an AJAX request for the Partial View for that URL, and swaps it into the element designated by contentSelector. Which, of course, will be our content area in the Layout page.

Finally, we need to wire this into our Layout page. Add Routing.js to our bundle, after Sammy.js:

bundles.Add(new ScriptBundle("~/js/mvc-spa").Include(
        "~/Scripts/jquery-{version}.js",
        "~/Scripts/sammy-{version}.js",
        "~/Scripts/Routing.js"));

Then, add the following script block to the Layout page, after rendering the bundle:

@Scripts.Render("~/js/mvc-spa")
<script>
$(function () {
    var routing = new Routing('@Url.Content("~/")', '#page', 'welcome');
    routing.init();
});
</script>

This instantiates a Routing instance with the root URL for the application (this becomes important if our app is deployed anywhere other than '/'), the selector of our content area ('#page'), and the route to default to when the user navigates to the root of the app. This should be the Partial View that inherited the original content from our Home/Index view, in step two.

Original version of this modified post published here:

http://blog.apterainc.com/bid/313071/Turn-your-ASP-NET-MVC-app-into-a-Single-Page-Application-with-one-classy-Sammy-js-route

 

Tags:

C# | MVC

Restore NUGET Packages in Visual Studio Online TFS Continuous Integration Builds

by 16. February 2015 13:25

http://geekswithblogs.net/TarunArora/archive/2014/09/14/auto-restore-nuget-packages-with-tfs-build-the-right-way.aspx

  • Step 1 - Enable NuGet Package Restore

        image

        Projects that use MSBuild-Integrated package restore typically contain a .nuget folder with three files:

    • NuGet.Config
    • NuGet.exe
    • NuGet.targets

Since the presence of a NuGet.targets file determines whether NuGet will continue to use the MSBuild-Integrated approach, this file must be removed. Also, as the .nuget\NuGet.exe file is not used by Automatic Package Restore, it likewise can be removed. By default, the NuGet.Config file instructs NuGet to bypass adding package binaries to source control. Automatic Package Restore will honour this as long as you leave this file in place. Note that NuGet.Config only has an effect when using Visual Studio to integrate with Team Foundation Server (TFS). In addition to these files, NuGet modifies the project files in the solution to reference the NuGet.targets file so it can participate in the build process. When migrating to Automatic Package Restore, these references must also be removed.

       Remove the NuGet.exe and NuGet.targets files from the solution's .nuget folder. Make sure the files themselves are also removed from the solution workspace.
       Retain the NuGet.Config file to continue to bypass adding packages to source control.

  • Step 2 – Close Down Visual Studio

        Each project in your solution that has picked up any of the below listed tags in the project properties will need to be removed. Open the project in Notepad and look for the below tags, remove these tags…

1. ------------------- 
<RestorePackages>true</RestorePackages>
----------------------

2. -------------------
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />  
----------------------

3. --------------------
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">  
    <PropertyGroup>
        <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, 
see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
------------------------
  • Step 3 – Open the solution and check in the changes

        Once you have made the above listed changes, you are good to check in the changes.

Trigger the  build now, the build server should now be able to successfully resolve the package references…

More details here… http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

Tags:

ASP.Net | TFS | Visual Studio

Microsoft ASP.Net Identity 2.1.0

by 10. January 2015 11:10

http://blogs.msdn.com/b/webdev/archive/2014/08/05/announcing-rtm-of-asp-net-identity-2-1-0.aspx

Tags:

Issue with ASP.Net Identity from Default Local File System Database to SQL Server Based Database

by 22. December 2014 10:12

I created a new MVC 5 web application with the "Individual User Account" option that configures the ASP.Net Identity model.  By default this uses Entity Framework Code First model with a local file system database created in the local App_Data folder.  I tried moving this to an actual SQL Server database location by creating the five dbo.aspnet_... tables and changing the web.config to point to the new location.  However, in doing so I received the error below.  Turns out to solve this I just needed to change the connection string in the web.config from the Entity Framework style to the basic style (see old vs. new connection strings below).

 <connectionStrings>

    <addname="NewSimpleConnection"connectionString="Data Source=SERVER_NAME_HERE;initial catalog=DB_NAME_HERE;user id=USER_ID_HERE;password=PASSWORD_HERE;Integrated Security=False"providerName="System.Data.SqlClient" />

    <addname="OldEtityFConnection"connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=SERVER_NAME_HERE;initial catalog=DB_NAME_HERE;user id=USER_ID_HERE;password=PASSWORD_HERE;MultipleActiveResultSets=True;App=EntityFramework&quot;"providerName="System.Data.EntityClient" />

  </connectionStrings> 

Server Error in '/' Application.


 

Unable to load the specified metadata resource.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource.

Source Error:

 

Line 114:      {
Line 115:        var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
Line 116:        IdentityResult result = await UserManager.CreateAsync(user, model.Password);
Line 117:        if (result.Succeeded)
Line 118:        {

Tags:

ASP.Net | C# | SQL Server