SQL Server

SQL Server

Problem

When migrating a Visual Studio project with a local SQL Server application database to IIS, you receive the following error:

“Failed to generate a user instance of SQL Server due to failure in retrieving the user’s local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.”

Resolution

In IIS, Select the appropriate application pool.  Change advanced settings->process model->Load User Profile value to true.

 

For more information about how Acumen can help with your software needs, contact us today!

 

Crystal Report

Crystal Report

Object reference not set to an instance of an object.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

CrystalReportSource1.ReportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, “Registration Reports”)

This occurs because the Login credentials provided are not valid.  In particular, you cannot change SERVER or DATABASE with

SetDatabaseLogon(User, Password, Server, Database)

See:   http://msdn.microsoft.com/en-us/library/ms227750(v=vs.80).aspx

Code:

              First:        Dim Server As String = ConfigurationManager.AppSettings(“DBServer”)

              Second:    Dim Database As String = ConfigurationManager.AppSettings(“Database”)

              Third:       Dim User As String = ConfigurationManager.AppSettings(“DBUser”)

              Last:         Dim Password As String = ConfigurationManager.AppSettings(“DBPassword”)

 

                ‘ The following set of code is necessary to dynamically change the SERVER and DATABASE.

                Dim ci As CrystalDecisions.Shared.ConnectionInfo = New ConnectionInfo()

                ci.Type = ConnectionInfoType.CRQE

                ci.ServerName = Server

                ci.DatabaseName = Database

                ci.UserID = User

                ci.Password = Password

                Dim tli As TableLogOnInfo = New TableLogOnInfo()

                tli.ConnectionInfo = ci

                Dim t As CrystalDecisions.CrystalReports.Engine.Table

                For Each t In CrystalReportSource1.ReportDocument.Database.Tables

                    t.ApplyLogOnInfo(tli)

                Next t

                CrystalReportSource1.ReportDocument.SetParameterValue(“@var1”, Request.QueryString(“param1”))

                ‘ The following will fail if the login fails:

                ‘        “Object reference not set to an instance of an object”

                ‘        “Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.”

                CrystalReportSource1.ReportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, “Registration Reports”)

 

For more information how Acumen can help with your software needs, contact us today!

Building additional SQL views in Aptify Association and Membership Management Software can sometimes require you to use SQL temporary tables in your view.

If you then attempt to create a database object from said view:

You will get an Aptify Exception error that will include “Views or functions are not allowed on temporary tables. Table names that begin with ‘#’ denote temporary tables.”

To get around this problem:

Take the T-SQL involving the temp table and port it into a table-based function that is called by the view.

The issue comes from the way Aptify enumerates everything returned by the SELECT statement and cannot handle temp tables in a view. Functions don’t have the same restrictions, though, and can be used to return the needed data.

See our Network Page or Contact Us to find more ways we can help you!

SSID

The new Microsoft API WinRT doesn’t allow you to list SSIDs regardless of user permissions.  While it can be done with Win32, it cannot be done with WinRT.  Remember that an App can’t enter the Store unless it is exclusively WinRT.  This means that there isn’t any advanced WiFi analysis Apps in the Windows 8 store.

On Android you can get this:

SSID: XYZ, BSSID: 00:1d:b3:4d:f0:db, capabilities: [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP-preauth], level: -90, frequency: 2452

For the “official” response:  http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/43cf36c0-a906-41b6-b6a3-8fd512a2b4fa

A lot of the stuff I learn about CSS is just from inspecting websites created by other developers. So, when I’m surfing along and something catches my eye, I will inspect the element, and sometimes look at the style sheet to see what is going on behind the scenes.

Today, I was looking at a site and saw that the H1 text was a non-standard browser font. We have been doing the Google font import thing and I was wondering if the developer of this site had imported the font from Google. So I inspected the H1, saw that it was a custom font and then I went to the style sheet to see where it had been imported from… to my surprise, it had not been imported from Google or a paid web font repository. It was a font stored in a local directory on the web server. This approach would be the equivalent of putting a fonts directory in the theme folder in a wordpress site, then setting up the stylesheet to use fonts in there.

Here is the code which was used to add the font to the style sheet:

 

@font-face {
font-family: 'DirtyHeadline';
src: url('fonts/dirty_headline-webfont.eot');
src: local('?'),
url('fonts/dirty_headline-webfont.woff') format('woff'), 
url('fonts/dirty_headline-webfont.ttf') format('truetype'), 
url('fonts/dirty_headline-webfont.svg#webfontzwLyc702') format('svg');
font-weight: normal;
font-style: normal;
}

I did some research on this method, and here is a breakdown of how it works.

  • @font-face — This tells the browser it will be providing support for a non-standard font.
  • font-family: ‘DirtyHeadline’; — This is a friendly reference name for the font. It can be anything. It is used to call the font as in: h1{font-family:DirtyHeadline;}
  • src: url(‘fonts/dirty_headline-webfont.eot’); — IE 5+ only supports the eot format. This tell the browser the font location and file name

I’m going to put the next part on separate lines so it is easier to understand. It could be implemented this way and would work fine.

  • src: local(‘?’), — When a browser displays a font like this, it actually downloads the font into a local cache. This tells the computer to assign a fictional name to the font as it loads it into the local cache, to avoid any possible collisions with locally installed fonts on the computer.
  • url(‘fonts/dirty_headline-webfont.woff’) format(‘woff’), — The .WOFF format (Newer Mozilla Browsers supports this) and the path to the WOFF file
  • url(‘fonts/dirty_headline-webfont.ttf’) format(‘truetype’), — ., the .TTF format (Older Mozilla Browsers, Safari, Opera, Chrome) and path to the TTF file.
  • url(‘fonts/dirty_headline-webfont.svg#webfont’) format(‘svg’); — the .SVG format for iPhone, Newer Chrome, and Opera browsers.

And lastly,

  • font-weight: normal; — Defines the default weight of the font. Needed for webkit browsers.
  • font-style: normal; — Defines the default style (italic, underline, strikethough, etc.)
  • Without these, Webkit browsers will ignore any weight or style commands and the designer won’t be able to assign weight values to the font when assigning it to an element definition.

After this setup is completed in the style sheet, you can call the font anywhere you want using it’s friendly name (as you normally would when assigning a font to a class or element, font-family:DirtyHeadline;).

With this information, it is easy to see how custom fonts can be used on websites, loaded from a local directory. This means you can use any font you want, as long as you have it in each required format (for cross browser support). For any font you want to use, you need a directory containing the EOT, WOFF, TTF, and SVG versions. So, what’s the trick? Finding a font in all of those versions can be tricky, but here is a site that provides a ton of “Kits” that contain everything needed to implement the font with cross browser support, FREE:

http://www.fontsquirrel.com/fontface

My resources:

  • http://sixrevisions.com/css/font-face-guide/
  • http://www.css3.info/preview/web-fonts-with-font-face/

Check out our CMS Design Page for more information about how we can make your site better!

Data Annotations

Summary:

You may have found code samples to generate your own Data Annotations handler for Web Forms.  You may have found incomplete or broken examples.  Stop.  Use this instead:  http://davalidation.codeplex.com/

You can do client validation in C# .Net using Data Annotations using this commonly referenced page by Gil Fink:

http://blogs.microsoft.co.il/blogs/gilf/archive/2010/04/08/building-asp-net-validator-using-data-annotations.aspx

From this article, it is important to note that the DataAnnotationValidator class MUST be in a Server Control project and referenced as an Assembly.  It is possible that this can be resolved by putting the class in App_Code and removing Assembly from your Register directive:

Create a new Web Server Control Project in your Solution.  Delete the automatically created class file and replace it with the contents from the web page listed above.

Reference the new Assembly/Project in your original Project.

 

If you try the App_Code technique you will need to change:

<%@ Register TagPrefix=”val” Namespace=”Validator” Assembly=”dotNetValidator” %>

to <%@ Register TagPrefix=”val” Namespace=”Validator” %>

Unfortunately, the App_Code technique didn’t work for me in Visual Studio 2010, which doesn’t want to make an App_code folder.

 

NOTE:  Here is similar code for client validation in VB:

http://adventuresdotnet.blogspot.com/2009/08/aspnet-webforms-validation-with-data.html#!/2009/08/aspnet-webforms-validation-with-data.html

    I have not tried this code and don’t know if it suffers from the same problem.  Perhaps it doesn’t in VB.net.

 

Unfortunately, the C# code doesn’t work because it tests the class Type in the Assembly instead of in the calling Web Project.  This causes an InvalidOperationException error in GetValidatedType. (The returned Type is null.)

This problem was noticed by Alex Ford on stackoverflow:  http://stackoverflow.com/questions/5600707/how-do-you-do-web-forms-model-validation. However, the posted solution has the same problem and wasn’t explained in detail.  But is does accurately describe the problem.  And ultimately, this code cannot get the PropertyName validation info necessary.  Stick with the original code.

Data Annotations Solution

So, how do you request a Type check against the calling Assembly?  I found this:  http://generally.wordpress.com/2007/06/01/typegettype-and-referred-assemblies/. Which accurately describes how to dictate the Assembly to search for the Type.

Referring back to Gil’s original article, this syntax was used but not explained.  The calling Assembly , and due to the brief code provided did not state the behaviour or syntax of SourceTypeName.

When using SourceTypeName, you MUST indicate the class name and the calling assembly like this:

<val:DataAnnotationValidator ID=”valID” runat=”server” ControlToValidate=”MyWebControlToValidate” PropertyName=”MyClassVariableToValidate” SourceTypeName=”MyClassToValidateAVariable, MyApplicationAssemblyName” /

 

Example:

<val:DataAnnotationValidator ID=”valID” runat=”server” ControlToValidate=”FirstName” PropertyName=”FirstName” SourceTypeName=”Person, MyWebApp”

 

For a completely different approach and a complete NuGet package: amanek.com/building-data-annotations-validator-control-with-client-side-validation/

To validate a control before submit: http://www.codeproject.com/Articles/185943/Validation-in-NET-Framework-4

See our Contact Page for more information!

I was working on our dotNetNuke site with a Navigation bar and added it to all pages. I then edited the Navigation bar, pulled off the Display on All Pages check box in the Settings dialog box, and then rechecked it. It would not display on all pages after this. This is apparently a bug in the DNN system and this is the workaround.

Go to Admin – Recycle Bin and Click “Empty Recycle Bin” button.

Then go back to the Module – Settings and recheck “Display on All Pages”. It should work.

I found help here.

Tom

See our CMS Development Page for more information on how we can help you!

JQuery

jqueryRotate is awesome, it can rotate images in every browser known to man. http://code.google.com/p/jqueryrotate/ Except that it breaks the ability to drag. (Easily fixable.)

Unfortunately, the crazy backflips necessary for IE7 and IE8 (VML) also breaks resizing because the image is actually hidden and a VML context is manipulated in it’s place.  This is not easily fixable. The crazy resolution is to manipulate the DOM to destroy and recreate the image on each resize attempt.

Here is the code: //

Destroy the image, cause once it has been rotated, it can’t be resized. myObj = document.getElementById(‘img1’); myPar = myObj.parentNode; myPar.removeChild(myObj);

// Recreate the image, cause we can’t do without it. var img = document.createElement(‘img’); document.getElementById(‘div1’).appendChild(img); img.setAttribute(‘id’, ‘img1’); img.setAttribute(‘src’,  ‘images/Image1.png’); img.setAttribute(‘style’, ‘position:absolute;’);

// Resize it $(“#img1”).css({ height: 99, width: 101 }); // Rotate it back $(“#img1”).rotate(rotValue); Kind of drastic, but hey it works.

See issue as reported by me (with fix): http://code.google.com/p/jqueryrotate/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=61

See our CMS Support Page for more information!

On Dec 29, 2011,   Microsoft released a security update KB2656356 / MS11-100 for ASP.NET to address a potential Denial of Service vulnerability.  In the update, Microsoft introduced a limit to the number of data elements on an ASP.NET form.   The default limit is 1000 data elements.   Exceeding the limit will cause a ThrowIfMaxHttpCollectionKeysExceeded error.

After applying the patch to your webserver, forms that exceed the limit will generate the following error when posting:

System.Web.HttpException: The URL-encoded form data is not valid. —> System.InvalidOperationException: Operation is not valid due to the current state of the object.

at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()

at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)

at System.Web.HttpRequest.FillInFormCollection()

To change the default MaxHttpCollectionKeys limit, add the following to your web.config file in the appSettings section and put a large value.  If it isn’t big enough, make it bigger:


<appsettings>

<add key=”aspnet:MaxHttpCollectionKeys” value=”2000″></add>

</appsettings>

References

Microsoft KB Article

December 2011 Out-Of-Band Security Bulletin Webcast Q&A

Stackoverflow Post

Keywords

.net dotnet appSettings asp.net

See our .Net Development Page for information on .net development consulting and outsourcing.