Cannot resolve the collation conflict between “Latin1_General_CI_AS” and “SQL_Latin1_General_CP1_CI_AS”

Cannot resolve collation conflict for equal to operation.

In MS SQL SERVER, the collation can be set at the column level. When compared 2 different collation column in the query, this error comes up.

SELECT ID
FROM ItemsTable
INNER JOIN AccountsTable
WHERE ItemsTable.Collation1Col = AccountsTable.Collation2Col

If columns ItemsTable.Collation1Col and AccountsTable.Collation2Col have different collation, it will generate the error “Cannot resolve collation conflict for equal to operation“.

To resolve the collation conflict add following keywords around “=” operator.

SELECT ID
FROM ItemsTable
INNER JOIN AccountsTable
WHERE ItemsTable.Collation1Col COLLATE DATABASE_DEFAULT
= AccountsTable.Collation2Col COLLATE DATABASE_DEFAULT

ASP.NET MVC4 “BIN” a reserved keyword?

I have a stock query application that returns data based upon a stock symbol.

Basically, the AJAX call goes to ~/Stocks/GetStockData/{id} where the {id} is the stock symbol.

This works fine… generally. Today I found that the stock “Progressive Waste Solutions Ltd.”, which has a symbol of BIN, blew up. Looking at the return data in the browser, I see it’s returning a 404 for this symbol.

It occurred to me that BIN might be a reserved word, asking for some binary file or something. Is this the case? How do I work around this without a whole lot of effort? Are there other keywords that will also cause this problem?

UPDATE

Per Artyom Neustroev, this could be a reserved keyword, and would be protected from routing to. He referenced an article which referenced a website which stated the way around this was to add the following configuration setting in the config file:

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>

    <!-- ... your other settings ... -->
  </system.web>
</configuration>

 

The routing mechanism takes into account hidden directories and files (like web.config, /bin, etc) and hides them from people. For some of these, the rules can be relaxed a bit, as they are handled in code. These “keywords” are: CON, COM1, COM2, COM3, COM4, LPT1, LPT2, AUX, PRN, and NUL. These can actually be referenced with a change to your web.config file as such:

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>

    <!-- ... your other settings ... -->
  </system.web>
</configuration>

Using LINQ And Converting DateTime To A String

The problem, I need the DateTime, but I really only need the date and I need to use it for something else.  Something that would like it to be a string.  How can I do this using LINQ?  Well it really isn’t all that hard.  If you try to use any of the .ToString or .To…. DateString you will get an error because it cannot do that in SQL.  Well don’t give up, you just need an extra step.

Basically you are going to get your data out of SQL before you try to convert that DateTime to a string.

First you do your normal LINQ query where you just get that DateTime, here is an example.

1
2
3
var vDates = (from d in oForm.tblSchedule
                      select new { scheduleDate = EntityFunctions.TruncateTime(d.dtSchedule) })
                      .Distinct();

Now here comes the fix.  Use something like the ToList() so that it iterates on it and is no longer in SQL.  Now you can use your .To…String methods.

1
2
3
4
5
var vDates = (from d in oForm.tblScheduleIn
                      select new { scheduleDate = EntityFunctions.TruncateTime(d.dtSchedule) })
                      .Distinct()
                      .ToList()
                      .Select(o => new {scheduleDate = o.scheduleDate.Value.ToShortDateString()});

Now I cannot claim credit for figuring this out on my own.

enable gzip compression asp.net

Web .Config

<system.webServer>
<httpCompression>
<scheme name=”gzip” dll=”%Windir%\system32\inetsrv\gzip.dll”/>
<dynamicTypes>
<add mimeType=”text/*” enabled=”true”/>
<add mimeType=”message/*” enabled=”true”/>
<add mimeType=”application/javascript” enabled=”true”/>
<add mimeType=”*/*” enabled=”false”/>
</dynamicTypes>
<staticTypes>
<add mimeType=”text/*” enabled=”true”/>
<add mimeType=”message/*” enabled=”true”/>
<add mimeType=”application/javascript” enabled=”true”/>
<add mimeType=”*/*” enabled=”false”/>
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression=”true” doDynamicCompression=”true”/>
</system.webServer>

 

 

 

Global ASAX

private void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
string contentType = Response.ContentType; // Get the content type.

// Compress only html and stylesheet documents.
if (contentType == “text/html” || contentType == “text/css”)
{
// Get the Accept-Encoding header value to know whether zipping is supported by the browser or not.
string acceptEncoding = Request.Headers[“Accept-Encoding”];

if (!string.IsNullOrEmpty(acceptEncoding))
{
// If gzip is supported then gzip it else if deflate compression is supported then compress in that technique.
if (acceptEncoding.Contains(“gzip”))
{
// Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
Response.Filter = new System.IO.Compression.GZipStream(Response.Filter, System.IO.Compression.CompressionMode.Compress);
Response.AppendHeader(“Content-Encoding”, “gzip”);
}
else if (acceptEncoding.Contains(“deflate”))
{
// Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
Response.Filter = new System.IO.Compression.DeflateStream(Response.Filter, System.IO.Compression.CompressionMode.Compress);
Response.AppendHeader(“Content-Encoding”, “deflate”);
}
}
}
}