1

THIS IS NOT A DUPLICATE

Because I am having error only after porting (direct copy of code) from one server to another. So, I know this code has been working for a long time. The only variables are VS2015 and SQL Server Enterprise.

I have an app that works perfectly on a Server running VS2010 and SqlExpress

I have ported to a server running VS2015 and Microsoft SQL Server Enterprise (64-bit)

On the new machine I keep getting this issue on the ExecuteReader line:

What does this error mean?

string sqlCommandText; 
        if (Master.G.AgentHandlesAllExchanges)
        {
            sqlCommandText = "SELECT [Symbol] FROM [" + AccountCode + "].[Orders] WHERE [Status] = 'NEW'";
        }
        else{
            sqlCommandText = "SELECT [Symbol] FROM [" + AccountCode + "].[Orders] WHERE [Exchange] = 'Equity' AND [Status] = 'NEW'";
        }

    if (conn.State != ConnectionState.Open)
    {
        Open();
    }

    using (SqlCommand command = new SqlCommand(sqlCommandText, conn))
    {

        Dependency = new SqlDependency(command);

        Dependency.OnChange += new OnChangeEventHandler(OnDependencyChange);

        using (SqlDataReader reader = command.ExecuteReader())
        {
            // Process the DataReader.
        }
    }

System.InvalidOperationException was unhandled by user code
HResult=-2146233079 Message=Internal connection fatal error. Error state: 15, Token : 1 Source=System.Data StackTrace: at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader() at Cobra.SqlPA.InitialiseDependencyWORK(Action onDependencyMethod) in C:\Projects\CobraPROD\CobraPROD\SqlPA.cs:line 251 at Cobra.SqlPA.InitialiseDependency(Action onDependencyMethod) in C:\Projects\CobraPROD\CobraPROD\SqlPA.cs:line 222 at Cobra.modelAgent1.calcSignal(SingleProductData MPD) in C:\Projects\CobraPROD\CobraPROD\Models.cs:line 2029 at Cobra.modelAgent1.NewOrdersCallBack() in C:\Projects\CobraPROD\CobraPROD\Models.cs:line 1857 at Cobra.SqlPA.OnDependencyChange(Object sender, SqlNotificationEventArgs e) in C:\Projects\CobraPROD\CobraPROD\SqlPA.cs:line 287 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Data.SqlClient.SqlDependency.EventContextPair.Invoke(SqlNotificationEventArgs args) at System.Data.SqlClient.SqlDependency.Invalidate(SqlNotificationType type, SqlNotificationInfo info, SqlNotificationSource source) at System.Data.SqlClient.SqlDependencyPerAppDomainDispatcher.InvalidateCommandID(SqlNotification sqlNotification) InnerException:

ManInMoon
  • 6,795
  • 15
  • 70
  • 133
  • 2
    Good. I wouldn't want to see this query run, eg if someone entered `SomeTable] where 1=0; Drop Table Users;--` as the AccountCode variable – Panagiotis Kanavos Apr 04 '18 at 13:16
  • Sorry? I don't understand what you mean – ManInMoon Apr 04 '18 at 13:17
  • He is talking about sql injection and unfortunately he is right! This is not a secure query. To respond your question, are you sure that your account name exists in your new sql server instance ? – Coskun Ozogul Apr 04 '18 at 13:18
  • Yes definitely. There is only 1 AccountCode at the moment, and this problem is intermittant. – ManInMoon Apr 04 '18 at 13:32
  • Possible duplicate of [What Causes "Internal connection fatal errors"](https://stackoverflow.com/questions/1155263/what-causes-internal-connection-fatal-errors) – TnTinMn Apr 04 '18 at 13:32
  • See edit. This is not a duplicate – ManInMoon Apr 04 '18 at 14:02
  • What's the `@@VERSION` of both SQL Servers? If your server isn't patched to the [latest available build](http://sqlserverbuilds.blogspot.com/), try that (or, if you can't, at least test against the developer edition of the same version to see if SQL Server is the problem). Patching .NET is another option, although that's a less likely source of trouble. Also, are you using the exact same database (as in backup-restore) on both servers, or is there variation in that? Your use of `AccountCode` as a custom schema (as opposed to the more common `dbo`) could trigger edge cases in the code. – Jeroen Mostert Apr 04 '18 at 15:12

1 Answers1

-1

Looks like a dotnet error.

https://referencesource.microsoft.com/#system/net/system/Net/HttpWebRequest.cs

    // For portability only
    public virtual bool AllowReadStreamBuffering {
        get {
            return false;
        }
        set {
            if (value) {
                throw new InvalidOperationException(SR.GetString(SR.NotSupported));
            }
        }
    }