Thursday, April 24, 2008

SharePoint Error: Access web datasheet is attempting to retrieve data from a different domain.

A user reported this error today on a custom list built using the Datasheet view. We both could open the view, but as soon as any changes were made, the error would popup:

Access web datasheet is attempting to retrieve data from a different domain...

I had recently moved the site collection from a server (let's call it Terrance) to a new server (let's call it Phillip). I have to assume that when the datasheet view was trying to save changes, it was posting to http://terrance... instead of http://phillip...

I did some searching and found the answer: Alternate Access Mappings. You'll find this in SharePoint Central Administration, under Operations, and Global Configuration.

I needed to add a new Internal URL for http://terrance for the default zone, which has a public URL of http://phillip

According to Microsoft's documentation, when someone visits the site using the internal URL, the the public URL for the zone will be returned to the browser. So, visiting http://terrance/default.aspx, returns http://phillip/default.aspx in the address bar of the browser and the page that exists there.

Adding this Alternate Access Mapping immediately solved the problem the datasheet view was having.

Specified Cast is Invalid using LINQ to SQL

I found a helpful troubleshooting option when debugging an error in some LINQ to SQL code.

I have a custom class in my designer called ActualHoursData and it has a few properties. This is not auto-generated from the designer but rather is used as a class to hold results from a method call to the database.

image

I have a simple ASP:Repeater on a Web Form bound to a LINQ to SQL method result that is essentially a collection of this class.

When I opened the Web form in a browser, I kept getting the "Specified Cast is Invalid" error, and the stack trace showed the error occurred during the databind.

I couldn't easily tell which column from the database was causing the issue, and as far as I could tell, the data types were correct. But I discovered that I can set each property's type to System.Object, instead of System.Decimal, and the code runs fine.

image

I was then able to revert each property's type back to the expected specific type, and I found which property that was really causing the problem.

Friday, April 18, 2008

Using WrenSoft's ZoomSearch engine on an ASP.NET Web site

Wrensoft makes a very affordable and easy to use search engine that you can plug into your existing Web site. There are a few versions that are supported directly (ASP, CGI, and Javascript), but you can also use it on an ASP.NET Web site.

There are some instructions located on Wrensoft's website, which will help you build a basic search.aspx page for querying your website. However, if you want to integrate the search form into your own theme or site with masterpages, you'll need to take another approach.

The key is to use an asp:Literal control, and place it wherever you'd like the search results to appear. You can then build your search.aspx page just like any other themed page on your site and consider the Literal control to act like a 'Search results' control.

Using the code provided by wrensoft we'll write the output to that Literal control instead of the Response stream.

First, add your literal wherever you want the results to appear.

   1: <p>
   2:     <asp:Literal ID="ZoomSearch" runat="server"></asp:Literal>
   3: </p>

Then insert the code below (written in VB) in the Page_Load event. Note the code is copied from wrensoft's page, but I've changed the last line to take the results from the CGI search and place them into the asp:Literal

   1: 'Code from Wrensoft.com:  http://www.wrensoft.com/zoom/support/aspdotnet.html#vbdotnet
   2:  
   3:         Dim paramStr As String = ""
   4:         Dim parampos As Integer = Request.RawUrl.IndexOf("?")
   5:         If (parampos >= 0) Then
   6:             paramStr = Request.RawUrl.Substring((parampos + 1))
   7:         End If
   8:         Dim psi As ProcessStartInfo = New ProcessStartInfo
   9:         psi.FileName = Server.MapPath("~/search/search.cgi")
  10:         psi.EnvironmentVariables("REQUEST_METHOD") = "GET"
  11:         psi.EnvironmentVariables("QUERY_STRING") = paramStr
  12:         psi.EnvironmentVariables("REMOTE_ADDR") = Request.ServerVariables("REMOTE_ADDR")
  13:         psi.RedirectStandardInput = False
  14:         psi.RedirectStandardOutput = True
  15:         psi.UseShellExecute = False
  16:         Dim proc As Process = Process.Start(psi)
  17:         proc.StandardOutput.ReadLine()
  18:         Dim zoom_results As String = proc.StandardOutput.ReadToEnd
  19:         ' read from stdout 
  20:         proc.WaitForExit()
  21:         ' Print the output 
  22:         Me.ZoomSearch.Text = zoom_results