The version of SQL Server in use does not support datatype 'date'

by Rod 29. October 2013 20:51

Hey everybody!

It's been a while since I last blogged... anything, so I decided to post something a bit odd that happened to me today.

I've been developing software for over 3 years, and overall involved in professional industry for over 5 years, yet everyday there is always something that amazes me and leaves me wondering how did this program ever work?

In this particular case, I ran into the error "The version of SQL Server in use does not support datatype 'date'" when trying to deploy a windows service that worked perfectly on my local environment. The error was appearing when calling a stored procedure with a datetime as an input parameter VIA LINQ.

After a bit of research, it appears that the "Date" datatype was added to SQL Server 2008 and this error might appear then. Before the datatypes were smalldatetime and datetime. So I verify this:

My local environment was running SQL Server 2008. Check

The server I was deploying to was running SQL Server 2005. Wonderful. Upgrading the SQL server to 2008 was not an option.

So another bit of research and I found such a simple solution that throws the WTF alarm off: I changed the Dbtype parameter definition on the generated DBML designer.cs file (go to definition on the offending method accessed from the datacontext) from "Date" to "Datetime".

In other words I changed this:

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.GetMethod")]
public ISingleResult<GetMethodResult> GetMethod([global::System.Data.Linq.Mapping.ParameterAttribute(Name = "UpdateDate", DbType = "Date")] System.Nullable<System.DateTime> updateDate)
{
 IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), updateDate);
 return ((ISingleResult<GetMethodResult>)(result.ReturnValue));
}

To
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.GetMethod")]
public ISingleResult<GetMethodResult> GetMethod([global::System.Data.Linq.Mapping.ParameterAttribute(Name = "UpdateDate", DbType = "Datetime")] System.Nullable<System.DateTime> updateDate)
{
 IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), updateDate);
 return ((ISingleResult<GetMethodResult>)(result.ReturnValue));
}

 

That's it! Problem solved.

Until the next time,

Stay programming my friends!

Tags:

ASP.NET | Linq | Software Development | SQL

Excel - Trim all cells

by Victor 31. May 2013 07:52

Here's a macro to trim all selected cells:

 

Sub TrimCells()
    Dim R As Range
    Application.EnableEvents = False
    On Error GoTo ErrH:
    If TypeOf Selection Is Excel.Range Then
        For Each R In Selection.Cells
            If R.HasFormula = False Then
                R.Value = Trim(R.Value)
            End If
        Next R
    End If
ErrH:
    Application.EnableEvents = True
End Sub

Tags: ,

Detecting the File Download Dialog in the Browser

by Victor 11. January 2013 19:22

I ran into a scenario in which I needed to know when a PDF file finished "rendering" to the browser. Actually, it was being served as an attachment. Either way, I needed to know when the client got the response back from the server. This stumped me for a while until I found this extremely useful block post describing a very elegant solution using a cookie. The gist of it is to create a token on the client side and send it to the server with your file request. I did it via the query string. On the server side, when the pdf is done, add a cookie with the value of the token. Back on the client side, poll for a cookie with the token. That's it! Check out the full explanation here.

Tags: ,

javascript | jQuery | Software Development | Web Development

Visual Studio Conditional Pre-Build Event

by Victor 9. January 2013 08:35

Say, for example, you want to execute a pre-build event if the current configuration is not Debug. Then you can do it like so:

 

if not '$(ConfigurationName)' == 'Debug' [YOUR PRE-BUILD STATEMENT]

Sorting with CanJS

by Victor 20. December 2012 18:06

I need to sort a list based on the selected value of a dropdown. I didn't find anything built in in CanJS. The can.Model.List does not have a sort method. Luckily, Curtis created a fiddle that does sorting. I adapted his code a bit and added the dropdown.

 

You can see the jsfiddle here

Tags: , ,

Web Development | javascript

"Invalid column name 'CreatedOn'" - Entity Framework Code First

by Victor 7. September 2012 16:53

I started getting this error in a production system a day ago but nothing had changed in that application. The application is a REST web service and hasn't been touched in months. BUT, I did deploy a different application that uses the same database. The new application uses Entity Framework 5.0 and the existing application uses 4.3. Also, the new application uses Code First Migrations so a new table called __MigrationHistory was automatically added. It turns out that the existing application had automatic migration enabled. So, all I had to do was turn that off using this line of code and redeploy the dll.

 

Database.SetInitializer<MyModelContext>(null);
 
I don't think automatic migrations should be enabled by default but I suppose some people would want it. Sometimes I think MS tries to put too many "automagic" features in their frameworks...

Tags: , ,

Entity Framework | Software Development | Web Development

Entity Framework 5.0!

by Victor 23. August 2012 01:33

Finally, Entity Framework 5.0 is out and it has a whole slew of new cool features. Well, they're cool in the sense that they're finally here but better late than never.

What’s New in EF5

EF 5 includes a number of new features and bug fixes to the EF4.3 release. Most of the new features are only available in applications targeting .NET 4.5, see the Compatibility section for more details.

  • Enum support allows you to have enum properties in your entity classes.
  • Spatial data types can now be exposed in your model using the DbGeography and DbGeometry types.
  • Performance enhancements - these are exciting. Essentially queries will be compiled automatically now. Read more here
  • Code First will now detect if you have LocalDb or SQL Express available for creating new databases. Visual Studio 2012 includes LocalDb, whereas Visual Studio 2010 includes SQL Express.
  • Code First will add tables to existing database if the target database doesn’t contain any of the tables from the model.

The EF Designer in Visual Studio 2012 also has some new features:

  • DbContext code generation for new models means that any new models created using the EF Designer will generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed. Existing models will not automatically change to DbContext code generation.
  • Multiple-diagrams per model allows you to have several diagrams that visualize subsections of your overall model. Shapes on the design surface can also have coloring applied.
  • Table-Valued functions in an existing database can now be added to your model.
  • Batch import of stored procedures allows multiple stored procedures to be added to the model during model creation.

 

Here's a link to the getting started page of Entity Framework if you're new to it or want to see how to use features like Migrations.

Tags: , , , ,

Entity Framework | Software Development

Rotating text using CSS

by Victor 15. August 2012 21:18

This is a short style rule to help you rotate text in your html page using CSS.

 

.rotated-text {
    width:100px; height:20px; line-height:20px;
    -moz-transform: rotate(310deg);  /* FF3.5/3.6 */
    -o-transform: rotate(310deg);  /* Opera 10.5 */
    -webkit-transform: rotate(310deg);  /* Saf3.1+ */
    transform: rotate(310deg);  /* Newer browsers (incl IE9) */
    /* IE8+ - must be on one line, unfortunately */    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.6427876096865394, M12=0.766044443118978, M21=-0.766044443118978, M22=0.6427876096865394, SizingMethod='auto expand')";      /* IE6 and 7 */    filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.6427876096865394, M12=0.766044443118978,            M21=-0.766044443118978, M22=0.6427876096865394, SizingMethod='auto expand');   /*    * To make the transform-origin be the middle of    * the object.      */
    zoom:1;
    background:#ccc;
    font-weight:normal;
    margin:0 0 0 0;
}

Tags: , , , , , ,

ASP.NET | CSS | CSS3 | IE | Safari Development | Web Development

Get Date Part from a SQL DateTime

by Victor 9. August 2012 01:21

No matter how many times I used this, I always seem to forget. So, how DO you get just the date part from a DateTime object in SQL? Easy, like this:

 

DECLARE @someDate DATETIME
SET @someDate = '08/08/2012 10:15AM'
SELECT CONVERT(VARCHAR, @someDate, 101)

 

Try it, you'll see

Tags: , ,

SQL

Objects to querystring parameters serializing with jQuery

by Rod 18. June 2012 18:32

Did you know that you can serialize a javascript object to a parametized query string? I didn't!

But that ability came really useful when I was in need to create a "widget" of a page I maintain, which ultimately calls a web service, but right before doing so, creates an object.

I had in front of me a dilemma: Reuse the existing logic and manage it somehow or reinvent the wheel. Then I remembered something a professor once told me: don't reinvent the wheel. So, I took a look at the logic, and was about to write some logic to convert the intermediate object into a querystring when I thought "maybe this already exists" and what do you know? It does! That simplified the effort quite a bit. Using this to deserialize the query string handled things on the other side, and I was in business!

As always,stay programming my friends!

Rod

Tags:

Web Development | jQuery

Powered by BlogEngine.NET 2.5.0.6

About Us

Wuji Touch is a software consulting firm based in Delray Beach, Florida. We specialize in Microsoft technologies, but we also have experience with Progress OpenEdge, iOS, and Android development. This is our blog. These are the tales of the pains and pleasures we experience daily in our journey through 1s and 0s.

Month List