Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ Specified Cast Not Valid
    primarykey
    data
    text
    <p>Not getting much info on this error, but I'm not using any casting in this specific code, so I'm pretty lost.</p> <pre><code> var dsn = Request.ServerVariables["HTTP_HOST"].Split('.').First(); using (var ctx = new SharedDataContext("switchcurrent")) { var dbDsn = ctx.SiteObjects.FirstOrDefault(s =&gt; s.DSN == dsn); if (dbDsn == null) { Session["CurrentDsn"] = "SwitchCurrent"; } else { Session["CurrentDsn"] = dbDsn.DSN; Response.Redirect(String.Format("~/{0}", dbDsn.DefaultPage)); } } </code></pre> <p>The LINQ statement is where I'm getting the error. If the statement returns null, the code continues fine, but if it's an actual match with an object in the database, I'm getting this error.</p> <p>EDIT (additional info)</p> <p>The error message is an InvalidCastException Stack trace:</p> <pre><code> at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)at System.Data.Linq.Table`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate) at WebApplication1.Default.SetCurrentDsn() in C:\Code\dir\Default.aspx.cs:line 163 at WebApplication1.Default.Page_Load(Object sender, EventArgs e) in C:\Code\dir\Default.aspx.cs:line 32 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) </code></pre> <p>SiteObject.Dsn is a string. and so is dsn.</p> <p>Basically if it is 'localhost' (which isn't in the db) the code passes, but if its a match ('pgande') this error is thrown.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload