Mapping a DataTable to an Object Class. Like a homemade Linq to SQL. Send over WCF to SilverLight

Application Foundation

An application I work has architecture in a way where we have a Class object that represents each table. So for example we might have a “Customer” table in the database. So our class would be something like..

Customer.vb class file…

Public Class Customer

    Private _FirstName As String = String.Empty
    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Private _LastName As String = String.Empty
    Public Property LastName() As String
        Get
            Return _LastName
        End Get
        Set(ByVal value As String)
            _LastName = value
        End Set
    End Property

End Class

In this class is a function to say list all customers, we call this “GetList” method. You might use another way to bring back a list of data. Ideally now we’d want to bring back Enumerable Lists, but the app was already structured for DataSets and DataTables. So I was trying to reuse what we had.

Customer.vb class file

Public Function GetList() As Data.DataTable
    Dim oDS As Data.DataSet
    Try
        oDS = DataAccess.SqlHelper.ExecuteDataset(_ConnectionString, Data.CommandType.StoredProcedure, "CustomerGetList")
        Return oDS.Tables(0)
    Catch ex As Exception
        Throw ex
    Finally
        oDS = Nothing
    End Try
End Function

So on our pages we might do something like this…

Default.aspx.vb

Protected Sub Button1_ClickSave()
    Dim oCustomer As New Customer
    oCustomer.FirstName = "Fred"
    oCustomer.LastName = "Mastro"
    oCustomer.SaveToDB()

    GridView1.DataSource = oCustomer.GetList()
    GridView1.DataBind()

    oCustomer = Nothing

End Sub

 

And this returns a nice DataTable and populates the grid. Great!

Problem Areas over WCF to SliverLight

I was working on a SilverLight application that would talk to an existing business application, to pull back and list records.  I had to use a Service, so I went with WCF since RIA.Net is not in production yet.  The problem was that DataTables can not be serialized and set over WCF to SilverLight.  So I tried messing with Linq to SQL to pull data back and populate classes I already had, but LinqTables are not serializable either, and instead of modifying all the Linq classes generated in my class I wanted to find an easier solution.

DataTable to List(Of Customer) Solution

I can across these two posts: Datatable to List of Objects Mapper and Creating datarow to object mapper and was amazed. Using reflection Chris Rock (lol) was able to read the properties of the object and map each column of the datatable to the desired property of the object. This is what I’m looking to do.  This would manually mimic Linq type functionality. The Bulk of the code is this

My Helper.vb class file

  1.  
  2. Public Class Helper
  3.  
  4.     Public Function MapDatarowToObject(Of T)(ByVal dr As DataRow) As T
  5.         Try
  6.  
  7.             If dr Is Nothing Then
  8.                 Return Nothing
  9.             End If
  10.  
  11.             Dim instance As T = Activator.CreateInstance(Of T)()
  12.  
  13.             Dim properties() As Reflection.PropertyInfo = instance.GetType().GetProperties()
  14.  
  15.             If (properties.Length > 0) Then
  16.                 For Each propertyObject As Reflection.PropertyInfo In properties
  17.  
  18.                     Dim valueSet As Boolean = False
  19.  
  20.                     For Each attributeObject As Object In propertyObject.GetCustomAttributes(False)
  21.  
  22.                         If attributeObject.GetType() Is GetType(MapperColumn) Then
  23.                             Dim columnAttributeObject As MapperColumn = CType(attributeObject, MapperColumn)
  24.  
  25.                             If (columnAttributeObject.ColumnName <> String.Empty) Then
  26.  
  27.                                 If dr.Table.Columns.Contains(columnAttributeObject.ColumnName) AndAlso Not dr(columnAttributeObject.ColumnName) Is DBNull.Value Then
  28.                                     propertyObject.SetValue(instance, dr(columnAttributeObject.ColumnName), Nothing)
  29.                                     valueSet = True
  30.  
  31.                                 End If
  32.  
  33.                             End If
  34.                         End If
  35.                     Next
  36.  
  37.                     If Not valueSet Then
  38.                         If dr.Table.Columns.Contains(propertyObject.Name) AndAlso Not dr(propertyObject.Name) Is DBNull.Value Then
  39.                             propertyObject.SetValue(instance, dr(propertyObject.Name), Nothing)
  40.                         End If
  41.                     End If
  42.  
  43.                 Next
  44.             End If
  45.  
  46.             Return instance
  47.         Catch ex As Exception
  48.             Throw ex
  49.         End Try
  50.     End Function
  51.  
  52.     Public Function MapDataTableToList(Of T)(ByVal dt As DataTable) As Collections.Generic.IList(Of T)
  53.         If dt Is Nothing Then
  54.             Return Nothing
  55.         End If
  56.  
  57.         Dim list As IList(Of T) = New List(Of T)
  58.  
  59.         For Each dr As DataRow In dt.Rows
  60.             list.Add(MapDatarowToObject(Of T)(dr))
  61.         Next
  62.  
  63.         Return list
  64.     End Function
  65.  
  66. End Class
  67.  
  68. <AttributeUsage(AttributeTargets.Property)> _
  69. Public Class MapperColumn
  70.     Inherits Attribute
  71.  
  72.     Private mColumnName As String
  73.  
  74.     Public Sub New(ByVal columnName As String)
  75.         mColumnName = columnName
  76.     End Sub
  77.  
  78.     Public Property ColumnName() As String
  79.         Get
  80.             Return mColumnName
  81.         End Get
  82.         Set(ByVal value As String)
  83.             mColumnName = value
  84.         End Set
  85.     End Property
  86.  
  87. End Class

Using Mapper in WCF

Now in my WCF Service methods I can just instantiate Customers like I always do in the normal application and apply the new Mapper method to get a List of the class objects.

WCFServiceMethods.vb file (which is code-behind to WCFServiceMethods.svc)

  1. Imports System.ServiceModel
  2. Imports System.ServiceModel.Activation
  3. Imports System.Runtime.Serialization 'For DataContract
  4. Imports System.Collections.Generic
  5.  
  6. <ServiceContract(Namespace:="")> _
  7. <ServiceBehavior(IncludeExceptionDetailInFaults:=True)> _
  8. <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
  9. Public Class WCFServiceMethods
  10.     <OperationContract()> _
  11.     Public Function GetCustomers() As Collections.Generic.List(Of Customer)
  12.         Dim oCustomer As New Customer
  13.  
  14.         Dim Customers As Collections.Generic.List(Of Customer)
  15.         Customers = Helper.MapDataTableToList(Of Customer)(oCustomer.GetList())
  16.  
  17.         oCustomer = Nothing
  18.         Return Customers
  19.  
  20.     End Function
  21. End Class

You’ll see in Line 15, I can take the DataTable and now create a List(Of Customer) object, which is serializable and send it over the wire.

Applying it in SilverLight or Other Application that uses your WCF Service

Assuming you referenced your WCF Service.. Now on my SilverLight app on a button click I can get the List of Customers and show it natively in a datagrid.

MainPage.xaml code-behind

Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSearch.Click
    Dim oWCFProxy As New WCFService.WCFServiceClient

    AddHandler oWCFProxy.GetCustomers, AddressOf oWCFProxy_GetCustomersCompleted
    oWCFProxy.GetCustomersAsync()

    oWCFProxy = Nothing

End Sub

Private Sub oWCFProxy_GetCustomersCompleted(ByVal sender As Object, ByVal e As WCFService.GetCustomersCompletedEventArgs)
    Dim Customers As Collections.ObjectModel.Collection(Of oWCFProxy.Customer)
    Customers = e.Result

    DataGrid1.ItemsSource = Customers
End Sub

Problem Area With Mapper Casting Types and Solution

So with all that above you should have enough to re-create all this. Read through Chris’ posts because it does a good job of explaining the mapper.  I ran into a problem with the mapper though on line 39. Problem is when it tries to map data from the database, it all comes back as a string, and you don’t know until run-time what System.Type you need, so you can’t CType or DirectCast by using System.Type.GetType(), so I had to create a crappy function to Throw ex check every possible combination. This the best way? I sure hope it isn’t. Hope to find a better solution for it but was pressed for time.

So what was my crappy solution? I don’t even want to post it haha. I swapped out line 39 and 28 with the a call to this method of 1531 lines of code.

Private Sub TryCastTypeToPropertyType(ByRef propertyObject As Reflection.PropertyInfo, ByRef instance As Object, ByRef dr As DataRow, ByRef ColumnName As String)

Try
'Try to Default Types
propertyObject.SetValue(instance, dr(ColumnName), Nothing)
Catch exDefault1 As InvalidCastException
Try
'Try to String
propertyObject.SetValue(instance, CType(dr(ColumnName), String), Nothing)
Catch exString1 As InvalidCastException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
March 2010

IIS7 Windows7/Server2008 ApplicationPoolIdentity Security Change from Network Service

 

Yeah this one got me.. http://learn.iis.net/page.aspx/624/application-pool-identities/

The change microsoft made to have AppPool now run as “ApplicationPoolIdentity” instead of Network service.

So if you normally give Network Service rights needed to your webapp, you now have to stop doing that and change it to

IIS AppPool\DefaultAppPool

Or

IIS AppPool\<NAME OF YOUR APPPOOL>

End of that.

 

 

 

 

  1. Open Windows Explorer
  2. Select a file or directory.
  3. Right click the file and select "Properties"
  4. Select the "Security" tab
  5. Click the "Edit" and then "Add" button
  6. Click the "Locations" button and make sure you select your machine.
  7. Enter "IIS AppPool\DefaultAppPool" in the "Enter the object names to select:" text box.
  8. Click the "Check Names" button and click "OK".

By doing this the file or directory you selected will now also allow the "DefaultAppPool" identity access.

20 jQuery Methods to use

 

Great post on Net.tutsplus on 20 Helpful jQery Methods you Should be Using.

  1. after() / before()
  2. change()
  3. Context
  4. data() / removeData()
  5. queue() / dequeue()
  6. delay()
  7. bind(), unbind(), live(), and die()
  8. eq()
  9. get()
  10.   grep()
  11.   Pseudo-Selectors
  12.   isArray() / isEmptyObject() / isFunction() / isPlainObject()
  13.   markArray()
  14.   map()
  15.   parseJSON()
  16.   proxy()
  17.   replaceAll() / replaceWith()
  18.   serialize() / serializeArray()
  19.   siblings()
  20.   wrap() / wrapAll() / wrapInner()

 

Of course see the original post on the details of each of these.

My Day at CodeCamp in Orlando 2010

This weekend I attended the Orlando .Net Code Camp, 2010.  It was really good and I’m glad I went.  I even won a book, Professional ASP.NET 4 in C# and VB in a raffle drawing; I never win stuff :) I want to say thanks Microsoft!

Silverlight Animations 101

by Henry Lee from www.newagesolution.net

My first class of the day. This was a good class for me, because I wanted to know more about Silverlight animation. Granted some of it I already knew from using Blend and recently developing a business tool in SL, such as the VisualStateManager, but other little things I picked up were nice to knows and stuff I would like to dive into more later when I have time.

Behavior Driven Development (BDD)

by Sean Chambers, files at http://github.com/schambers/orlandocodecamp2010
http://www.lostechies.com/blogs/sean_chambers/

This was a great class in learning a new way of thinking and testing.  Developing test cases and application requirements from the outside in. Similar to GWT (Given When Then). I got a lot of good info from this on BDD vs TDD.  A neat tool that was mentioned was SpecUnit which reads your BDD and generates a cool Html document from it.  Also, due to the nature of Ruby on Rails, there is a good book on BDD for Ruby. Though it’s for Ruby, the theory is the same. It was recommended. The RSpec Book.  The method was developed by Dan North.

Some tools mentioned were CruiseControl.Net, Resharper or Coderush templates and Autokey Bdd.

Successfully Running Your Own Business

by Paul Swengler

Good class for someone that’s never run or had a business before. I thought I’d get something out of it, but unfortunately I already knew all the info. Went over a lot of basics and obvious that people overlook.

WCF RIA Services

by John McFetridge http://jmcfetridge.blogspot.com/

I’m sorry John, but I had to walk out of the class. I just couldn’t sit in there anymore.  I’ve already developed SL apps talking with WCF but not with RIA or Entities or Domain Service. However, this class was way to fast and just all over the place that it hurt my head and I had to leave. Best thing I got out of it was Saurabh Pant’s weblog.

From there I went into a jQuery class halfway in, but already knew the material.

Introduction to Azure and SQL Azure

by Joe Healy http://dfwiki.devfish.net

Now, this was a great class. Great and better understanding of Azure since the first time I sat in on it, when it was still fresh out the womb at Microsoft.  Makes so much sense for small companies or even large ones to have tools developed that can be scaled to fit sudden bursts and spikes in traffic for a fraction of the cost if you were to house your own sever farm. SQL for Azure has come a long way as well and it was exciting to see it in action.  There’s also the free pricing model for small apps and testing.

I got a lot of information out of this class. Some things I want to look up for later is Jeff Bernes’ case study as he in Tampa like myself.   Jim Zimmermon and the Tampbay.net group.  Using Bizspark or Website Spark to get access to the MSDN and 8 months of Azure for free.

Note, need to use SQL Manager R2 with Azure and also I want to look more into SQL 2008 Geospacing. 

Local SQL to SQL Azure and SQL Azure to local SQL tool, SQLAzureMW at codeplex.

Understanding Lambda’s in .Net

by Scott Dorman at http://geekswithblogs.net/sdorman/

This was about Lambda expressions in C#. Was good but since I mainly develop in VB.Net, just made me a little jealous :p

Design for Developers

by Diane Leeper at http://www.dianeleeper.com/ and blog at http://www.42stars.com/blog/

This was another great class where I walked away with a lot of information on design. She gave out 5 rules.

#1 – Alignment & Grid
#2 – Focus
#3 – Art
#4 – Pictionary
#5 – Community

I won’t dive into those and take away her thunder but it will help me remember. Some books that were recommended.  Drawing on the Right Side of the Brain, also The Back of the Napkin, which is more up my alley.

Some community links she gave out..

http://abduzeedo.com/
http://www.smashingmagazine.com/
http://www.visitmix.com/
http://2009.max.adobe.com/online/
http://videos.visitmix.com/
http://www.microsoft.com/design/toolbox

The End

And that about wraps it up.  Also, came across Russ there who does Silverlight training. http://www.russtoolshed.net/

They say it will all be on Channel9 soon at msdn.

Shrinking Silverlight XAP Files

Was looking for several ways to shrink my 2mb Silverlight XAP file.

Preferences-system.svgI ran across ComponentOne’s XAPOptimzer. However, the online demo failed considerably.  I uploaded my 2mb file and then it just timed out. Tried it twice.

image

Preferences-system.svgGiving up on that I came across Delay’s XAP Shrinker.  The thing I didn’t like about this one is that it requires you to have a zip and unzip in the same folder.  This, though you can auto run after your build which is nice.

Preferences-system.svgThe third tool I came across, ReXapper, which used the same concept as Delay’s but had everything built in and you could run from visual studio. This is the source code, you can compile the etc..

I created a very small application called ReXapper.exe which can do exactly the same as Delay describes but there is no external archiving utility necessary. It uses the SharpZipLib to re-zip the file. So there's just a tiny (124 kb) command-line executable.”  

However, upon using this my xap file actually GREW in size!! (XAP file is rexapped, old size: 2120567, new size: 2120605, time: 439) wtf lol scary.  So back to the drawing board.  I’ve read about using PNG compressors also to shrink your images down.

Nuvola apps edu languages.gifAlso found a good post on it here.

Optimizing Pages that use Telerik Controls. Mainly RadGrid

 

I was watching a webcast on Telerik TV, it’s called Optimizing RadGrid for ASP.NET Ajax.  There is a lot of useful information there. I summarized a bunch of it.

On my test page I…

  • Added Browserfile...
    • Compressing ViewState for RadTelerik controls  (Dropped viewstate considerably from sample page, 50,776 bytes to 5,428 bytes)
  • Added RadCompression for AJAX Calls to drop traffic size on ajax post-backs (Not handled by IIS compression)
  • Reduce Request using StyleManager and RadScriptManager
    • Added RadStyleSheetManager to MasterPage (Combines all CSS sheets into one download to limit requests)
    • Switched to RadScriptManager on Masterpage instead of ScriptManage
      • Request dropped from 71 to 47

 

Summarized Tips

  • Bind Grid Data on PreInit event, this will keep data from going to the ViewState and cut down on page size
  • If the Grid is ReadOnly and no editing takes place, then turn off viewstate for the Grid. EnableViewState="False"
    • Features that will NOT work when viewstate is off
      • Custom Edit Forms (User Control or Form Template)
      • Filtering
      • Grouping
      • Using Cached Data and Paging Together
    • Features that WILL work when view state is off
      • Indexes of Selected Items
      • Indexes of Edited Items
      • Group-by Expressions and Settings (but not the expanded state of grouped items)
      • Sort Expressions
      • Style Properties (But not if applied to a single cell or row in ItemDataBound event)
      • Column Order and other column properties
      • All settings concerning hierarchy structure (but not the expanded state of the items)
  • Optimized Column Editors on Grid
    • Used Shared Data Picker for Date columns in your grid
      • This requires a hidden data picker on page, and template column with textbox that uses js to talk to the datepicker with client-api (See Example Here)
    • Use Template column for comboxes and use Load-On-Demand
  • Ajaxify the Grid
    • Compresses Ajax calls which IIS misses, use RadCompression to drop traffic size
    • Use StyleManager and ScriptManager to bundle all css and scripts into one call each to server
  • More Tips Here
  • Other Ways to Optimize
    • Client-side Binding
    • Custom Paging
    • Virtual Scrolling
    • Caching Data server-side
    • Hierarchy Load modes
    • Group load modes
    • Filtering
    • .NET 3.5 + Linq
    • Upgrade from IE6

 

Other Controls

  • Other Controls
    • Use Shared Data Picker
    • Use RadInputManager if you want Validated or Stylized instead of using the the RadNumeric or RadTextbox controls
    • Use Load-On-Demand RadComboboxes
    • On RadMultiPage set RenderSelectedPageOnly = True
    • Hide Grid's with Visible="False" not with surrounding Div's set to display none.
      • Hiding the Grid itself, it doesn't render or get bound, grid will get data when visible is set to true again.
  • Add App_Browsers folder with a file that has.. (This one is HUGE, dropped my page significantly)
    • Create a file and add
    • <browsers>
          <browser refID="Default">
              <controlAdapters>
                  <!--<adapter controlType="System.Web.UI.Page" adapterType="Telerik.Web.UI.RadHiddenFieldPageStateCompression" />-->
                  <adapter controlType="System.Web.UI.Page" adapterType="Telerik.Web.UI.RadSessionPageStateCompression" />
              </controlAdapters>
          </browser>
      </browsers>

EventID 4625 on Windows 2008 IIS7 Windows Authentication Error

I was having wierd authentication issues on a Windows 2008 server with IIS7. I was trying to use Windows Authentication.  Worked fine from a remote location but failed when local on the server.

An account failed to log on.

Subject:
    Security ID:        NULL SID
    Account Name:        -
    Account Domain:        -
    Logon ID:        0x0

Logon Type:            3

Account For Which Logon Failed:
    Security ID:        NULL SID
    Account Name:        xxxxxx
    Account Domain:        xxxxxx

Failure Information:
    Failure Reason:        An Error occured during Logon.
    Status:            0xc000006d
    Sub Status:        0x0

Process Information:
    Caller Process ID:    0x0
    Caller Process Name:    -

Network Information:
    Workstation Name:    xxxx-xxxxxx
    Source Network Address:    ###.###.###.###
    Source Port:        49597

Detailed Authentication Information:
    Logon Process:       
    Authentication Package:    NTLM
    Transited Services:    -
    Package Name (NTLM only):    -
    Key Length:        0

This event is generated when a logon request fails. It is generated on the computer where access was attempted.

The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe.

The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network).

The Process Information fields indicate which account and process on the system requested the logon.

The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.

The authentication information fields provide detailed information about this specific logon request.
    - Transited services indicate which intermediate services have participated in this logon request.
    - Package name indicates which sub-protocol was used among the NTLM protocols.
    - Key length indicates the length of the generated session key. This will be 0 if no session key was requested

I found the solution on the MS Support site, Q89681.  Which suggested to turn off the LoopbackCheck.

To set the DisableLoopbackCheck registry key yourself, follow these steps:

  1. Set the DisableStrictNameChecking registry entry to 1. For more information about how to do this, click the following article number to view the article in the Microsoft Knowledge Base:

    281308 Connecting to SMB share on a Windows 2000-based computer or a Windows Server 2003-based computer may not work with an alias name

  2. Click Start, click Run, type regedit, and then click OK.
  3. In Registry Editor, locate and then click the following registry key:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa

  4. Right-click Lsa, point to New, and then click DWORD Value.
  5. Type DisableLoopbackCheck, and then press ENTER.
  6. Right-click DisableLoopbackCheck, and then click Modify.
  7. In the Value data box, type 1, and then click OK.
  8. Quit Registry Editor, and then restart your computer.

Texting In Public

If you're in a situation where you'd excuse yourself to go to the bathroom, you should also excuse yourself before reaching for your phone.  Otherwise, go ahead without asking.  Either way, don't play with your phone longer then you'd stay in the bathroom. - Farhad Manjoo (www.Tampabay.com)

  • Nothing)
    Catch exDate1 As ArgumentException
    'Try to Decimal
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
    Catch exDecimal1 As ArgumentException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    Catch exDecimal2 As InvalidCastException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    End Try
    Catch exDate2 As InvalidCastException
    'Try to Decimal
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
    Catch exDecimal1 As ArgumentException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    Catch exDecimal2 As InvalidCastException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    End Try
    End Try
    End Try
    Catch exString2 As ArgumentException
    'Try to Integer
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
    Catch exInt32a As ArgumentException
    'Try to DateTime
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
    Catch exDate1 As ArgumentException
    'Try to Decimal
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
    Catch exDecimal1 As ArgumentException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    Catch exDecimal2 As InvalidCastException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    End Try
    Catch exDate2 As InvalidCastException
    'Try to Decimal
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
    Catch exDecimal1 As ArgumentException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    Catch exDecimal2 As InvalidCastException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    End Try
    End Try
    Catch exInt32b As InvalidCastException
    'Try to DateTime
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
    Catch exDate1 As ArgumentException
    'Try to Decimal
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
    Catch exDecimal1 As ArgumentException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    Catch exDecimal2 As InvalidCastException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    End Try
    Catch exDate2 As InvalidCastException
    'Try to Decimal
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
    Catch exDecimal1 As ArgumentException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    Catch exDecimal2 As InvalidCastException
    'Try to Double
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
    Catch exDouble1 As ArgumentException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    Catch exDouble2 As InvalidCastException
    'Try to Boolean
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
    Catch exBoolean1 As ArgumentException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    Catch exBoolean2 As InvalidCastException
    'Try To Date
    Try
    propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
    Catch ex As Exception
    Throw ex
    End Try
    End Try
    End Try
    End Try
    End Try
    End Try
    End Try
    End Try
    End Sub

Maybe I’ll get lucky and someone will post up a “Oh you can just do this, which is new in .Net 3.5 or 4.0.. “ and I can get rid of this thing. But hey it works!

Resource: How to Consume WCF and ASP.Net Web Services in Silverlight

Comments are closed