Skip to content

Restore a SQL Server Backup to LocalDB

Found help here:

Thank you Rob!

  1. Open the “SQL Server Object Explorer” window in Visual Studio
  2. Right-click on the “(LocalDB)\MSSQLLocalDB”-node and choose “New Query…”
  3. The “master” database should be selected one
  4. Run the following query (the query will only present information):
            RESTORE FILELISTONLY
            FROM DISK = ‘D:\MyDatabase.bak’;
  5. In the result use the names in the LogicalName-column
            MyDatabase (mdf)
            MyDatabase_log (ldf)
  6. Run the following query:
            RESTORE DATABASE MyDatabase
            FROM DISK = ‘D:\MyDatabase.bak’
            WITH MOVE ‘MyDatabase’ TO ‘D:\MyDatabase.mdf’,
            MOVE ‘MyDatabase_log’ TO ‘D:\MyDatabase.ldf’,
            REPLACE;

System.Web.Optimization: Issues using IItemTransform when optimizations are enabled

I have a project where I use Web Essentials/Web Compiler to generate css from less. The default setting in Web Compiler is to create *.min.css files.

So in my project I have:

  • Style/Main.less
  • Style/Main.css
  • Style/Main.min.css

If I have these lines in my bundle configuration method:

  • BundleTable.EnableOptimizations = false;
  • BundleTable.Bundles.Add(new StyleBundle(“~/Style-bundle”).Include(“~/Style/Main.css”, new CssRewriteUrlTransform()));

CssRewriteUrlTransform will be called

If I have these lines in my bundle configuration method:

  • BundleTable.EnableOptimizations = true
  • BundleTable.Bundles.Add(new StyleBundle(“~/Style-bundle”).Include(“~/Style/Main.css”, new CssRewriteUrlTransform()));

CssRewriteUrlTransform will NOT be called

I want CssRewriteUrlTransform to be called when optimizations are enabled. It’s then I really want it.

I googled and found this:

The solution there works. I started to search in Reflector for “min” and found this property:

  • BundleTable.Bundles.FileExtensionReplacementList

So if I have these lines in my bundle configuration method:

  • BundleTable.EnableOptimizations = true;
  • BundleTable.Bundles.FileExtensionReplacementList.Clear();
  • BundleTable.Bundles.Add(new StyleBundle(“~/Style-bundle”).Include(“~/Style/Main.css”, new CssRewriteUrlTransform()));

CssRewriteUrlTransform will be called

Fonts not showing up in IE 11 on Windows 10

On a site using glyphicons the fonts did not show up in IE 11 on Windows 10. When I looked in the console in F12-developmenttools I found these entries:

  • CSS3111: @font-face påträffade ett okänt fel.
    fontawesome-webfont.woff
  • CSS3114: @font-face misslyckades med kontrollen av OpenType-inbäddningsbehörighet. Behörigheten måste vara Installable.
    glyphicons-halflings-regular.ttf

I searched and found this:

leading to this

I also found this:

In the Local Group Policy Editor (gpedit.msc) you can set this option. For me it was a group-policy set in the domain. Changing the setting requires a restart.

The setting on my swedish machine I found here in the Local Group Policy editor:

Datorkonfiguration/Administrativa mallar/System/Åtgärdsalternativ – Blockering av teckensnitt som inte är betrodda

“Block Untrusted Fonts” is something to search for.

Virtualize your physical machine

Before you get rid of your old physical machine it can be good to convert it to a virtual machine. If you forget to backup something from your old machine you can get it through your virtual machine later. If you want to convert your physical windows-machine to a virtual machine you can use free applications:

LocalDB reset

I have been working with SSDT and LocalDB for a while now. I like it. I run Visual Studio 2013, Update 4 and SQL Server Data Tools 12.0.50512.0 (2014). Today I noticed, under the (LocalDB)\v11.0 instance in the SQL Server Object Explorer, multiple databases that no longer existed on disk. They were databases I worked with earlier but then I deleted them. Trying to expand one of those databases said something like: “Could not connect to…”. The databases did not have any content-nodes under it. I started searching for “LocalDB reset” to find a way to get rid of all outdated databases listed. I found this:

I also found a comment somewhere (dont remember where) that said it should be possible to remove the instance-directory here:

  • C:\Users\USERNAME\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances

I took a copy of all the content under C:\Users\USERNAME\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances and then I deleted all the directories. And as I can see it works, when connecting to an instance via SQL Server Object Explorer, the directories are recreated.

In my case there are three directories:

  • MSSQLLocalDB – for the (LocalDB)\MSSQLLocalDB instance
  • ProjectsV12 – for the (LocalDB)\ProjectsV12 instance
  • v11.0 – for the (LocalDB)\v11.0 instance

To be sure no files are locked in the instance-directories when you try to delete:

  • Shut down all Visual Studio instances
  • Open taskmanager and stop all sqlservr.exe processes

As you start to connect to your databases again they show up under the associated instance again. It seem to work.

Another directory you can delete, to cleanup, is:

  • C:\Users\USERNAME\AppData\Local\Microsoft\VisualStudio\SSDT

When you start debugging, F5, a SQL Server Database Project, a database is created/updated in this directory. If you have deleted SQL Server Database Projects it can be useful to clean this directory too.

Important

This is mainly a reminder for my self. I am not sure if it is correct. So if you do it, you do it at your own risk.

Troubleshooting EPiServer search indexing-service

In a project I am working in we have experienced problems getting the EPiServer search indexing-service to work. We do not use EPiServer search as search-engine for the users. We just want to use it to be able to search in edit-mode, eg. search for page-id and page-name. We have a load-balanced environment with two “user-surf-nodes” and one edit-node. EPiServer search is just configured on the edit-node. The edit-node was first configured like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    ...
    <episerver.search active="true">
        <namedIndexingServices defaultService="IndexingService">
            <services>
                <add name="IndexingService" accessKey="local" baseUri="http://HOSTNAME/Services/IndexingService.svc" />
            </services>
        </namedIndexingServices>
        ...
    </episerver.search>
    ...
</configuration>

We could not get indexing to work. We had to configure it with the machine-specific ip, like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    ...
    <episerver.search active="true">
        <namedIndexingServices defaultService="IndexingService">
            <services>
                <add name="IndexingService" accessKey="local" baseUri="http://xxx.xxx.xxx.xxx/Services/IndexingService.svc" />
            </services>
        </namedIndexingServices>
        ...
    </episerver.search>
    ...
</configuration>

We also have a “Services”-directory in the project where we put the IndexingService.svc and System.Web.Http.ApiController-services (client-json-services). We dont want anonymous access to the client services so we have the following section in “Web.config”:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    ...
    <location path="Services">
        <system.web>
            <authorization>
                <deny users="?" />
            </authorization>
        </system.web>
    </location>
    ...
</configuration>

With this set the search index could not be created. The path to “IndexingService.svc” have to allow anonymous access. So we had to add the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    ...
    <location path="Services/IndexingService.svc">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
            ...
        </system.web>
        ...
    </location>
    ...
</configuration>

Summary

  • If you have a load-balanced environment try to configure the baseUri with a machine-specific IP-number or a machine-specific hostname instead of the load-balancer hostname, eg. http://xxx.xxx.xxx.xxx/&#8230; or http://hostname-node-a/&#8230;.
  • You have to allow anonymous access to the path of the baseUri.

Troubleshooting

An easy way to verify if the index is created or not is to see if the index-directory is created or not. If you have the directory try to remove it and see if it is recreated. Our index-directory was not created. The index-directory is configured here:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    ...
    <episerver.search.indexingservice>
        ...
        <namedIndexes defaultIndex="default">
            <indexes>
                <add name="default" directoryPath="[appDataPath]\Index" readonly="false" />
            </indexes>
        </namedIndexes>
    </episerver.search.indexingservice>
    ...
</configuration>

To troubleshoot I temporarilly set the log4net-configuration file content to this:

<?xml version="1.0" encoding="utf-8"?>
<log4net>
    <appender name="SearchSettingsAppender" type="log4net.Appender.RollingFileAppender">
        <appendToFile value="true"/>
        <datePattern value=".yyyyMMdd.'log'"/>
        <encoding value="utf-8"/>
        <file value="..\Application-Data\Logs\SearchSettings.log"/>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread], level = %level, logger = %logger: %message%n"/>
        </layout>
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
        <rollingStyle value="Date"/>
        <staticLogFileName value="true"/>
    </appender>
    <logger name="SearchSettings">
        <appender-ref ref="SearchSettingsAppender" />
        <level value="All" />
    </logger>
</log4net>

Then I tried to reindex with this feature:

To really start the reindexing I had to click the “Start Indexing” button multiple times. The request should start to process for a longer time. If the request finishes immediately, try click the button again.

When we had problems configuring the indexing-service by hostname, the following lines in the log-file helped:

  • Update batch could not be sent to service uri ‘http://HOSTNAME/Services/IndexingService.svc/update/?accesskey=local&#8217;. Message: ‘The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. at System.Net.HttpWebRequest.GetResponse()
    at EPiServer.Search.RequestHandler.MakeHttpRequest(String url, NamedIndexingServiceElement namedIndexingServiceElement, String method, Stream postData, Action`1 responseHandler)
    at EPiServer.Search.RequestHandler.SendRequest(SyndicationFeed feed, String namedIndexingService, Collection`1 ids)’
  • Could not reset index ” for service uri ‘http://HOSTNAME/Services/IndexingService.svc/reset/?namedindex=&accesskey=local&#8217;. Message: The underlying connection was closed: An unexpected error occurred on a receive. at System.Net.HttpWebRequest.GetResponse()
    at EPiServer.Search.RequestHandler.MakeHttpRequest(String url, NamedIndexingServiceElement namedIndexingServiceElement, String method, Stream postData, Action`1 responseHandler)
    at EPiServer.Search.RequestHandler.ResetIndex(String namedIndexingService, String namedIndex)

When we had problems with access to the indexing-service, the following lines in the log-file helped:

  • Update batch could not be sent to service uri ‘http://xxx.xxx.xxx.xxx/Services/IndexingService.svc/update/?accesskey=local&#8217;. Message: ‘The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. at System.Net.HttpWebRequest.GetResponse()
    at EPiServer.Search.RequestHandler.MakeHttpRequest(String url, NamedIndexingServiceElement namedIndexingServiceElement, String method, Stream postData, Action`1 responseHandler)
    at EPiServer.Search.RequestHandler.SendRequest(SyndicationFeed feed, String namedIndexingService, Collection`1 ids)’
  • Could not reset index ” for service uri ‘http://xxx.xxx.xxx.xxx/Services/IndexingService.svc/reset/?namedindex=&accesskey=local&#8217;. Message: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse()
    at EPiServer.Search.RequestHandler.MakeHttpRequest(String url, NamedIndexingServiceElement namedIndexingServiceElement, String method, Stream postData, Action`1 responseHandler)
    at EPiServer.Search.RequestHandler.ResetIndex(String namedIndexingService, String namedIndex)

EPiServer upgrade problems

I am going to upgrade an EPiServer site from 5.2.375.133 to 8 (8.7.0). I have stumbled into some problems when testing the upgrade. So this is my reminder.

Upgrading from 5.2.375.236 to 6.0.530.0

If you have a location-element, e.g. <location path=”.”></location> around your root system.web and/or system.webServer elements, remove it. You can readd it after the upgrade. The web.config file will not be upgraded correctly if you have that root-location-element. There is no exception in the upgrade-log.

After an application-restart (iisreset or application-pool-recycle) I got the following exception going to the start-page:

[NullReferenceException: Object reference not set to an instance of an object.]
EPiServer.WorkflowFoundation.AspNetWorkflowManager..ctor() +451
EPiServer.WorkflowFoundation.WorkflowManagerFactory.GetWorkflowManager(WorkflowSettingsElement configuration) +79
EPiServer.WorkflowFoundation.WorkflowSystem.StaticInitialization(Object sender, EventArgs e) +147
EPiServer.Web.InitializationModule.NotifyFirstBeginRequest(Object sender, EventArgs e) +284

[InvalidOperationException: Exception during intialization]
EPiServer.Web.InitializationModule.NotifyFirstBeginRequest(Object sender, EventArgs e) +391
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

The following requests gave the following exception:

[NullReferenceException: Object reference not set to an instance of an object.]
EPiServer.Web.UrlRewriteModule.HttpUrlRewriteToInternal(UrlBuilder url) +316
EPiServer.Web.UrlRewriteModuleBase.BeginRequestEventHandler(Object sender, EventArgs e) +203
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +79
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +170

Removing the root-location-element, before the upgrade, resolved the problem.

Upgrading from 6.1.379.0 (6.1.379.1001) to 7.0.586.1

You should have a EPiServerLog.config file, with a <log4net> element as root-element, in your application-root. The upgrade expects that file.

I did not have it and I got the following exception in the upgrade-log:

Get-Content : Cannot find path ‘C:\Data\Projects\ApplicationName\Site\EPiServerLog.config’ because it does not exist.
At C:\Program Files (x86)\EPiServer\CMS\7.0.586.1\Upgrade\System Scripts\Upgrade Site To 7 (SqlServer).ps1:320 char:34
+ $logConfigDoc = [xml](Get-Content <<<< $targetLogConfigFile)
+ CategoryInfo : ObjectNotFound: (C:\Data\Project…erverLog.config:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

An unhandled error has occured:
You cannot call a method on a null-valued expression.
When executing

At C:\Program Files (x86)\EPiServer\CMS\7.0.586.1\Upgrade\System Scripts\Upgrade Site To 7 (SqlServer).ps1:321 char:52
+ $logConfigRootNode = $logConfigDoc.SelectSingleNode <<<< (“/log4net”)

=
Get-EPiIsBulkInstalling
An error has occured and the transaction will be rolled back
Rolledback

At C:\Program Files (x86)\EPiServer\CMS\7.0.586.1\Upgrade\System Scripts\Upgrade Site To 7 (SqlServer).ps1:321 char:52
+ $logConfigRootNode = $logConfigDoc.SelectSingleNode <<<< (“/log4net”)
System.Management.Automation.ParentContainsErrorRecordException: You cannot call a method on a null-valued expression.