Monday 7 August 2017

Validateconnectionforexecute


Sto avendo il seguente messaggio di errore e sto usando petaPOCO. Perché ho questo messaggio di errore e cosa sto facendo sbagliato avere questo messaggio: System. InvalidOperationException è stato catturato MessageThere è già un DataReader aperto associato con questo comando che deve essere chiuso prima. SourceSystem. Data StackTrace: a System. Data. SqlClient. SqlInternalConnectionTds. ValidateConnectionForExecute (SqlCommand di comando) a System. Data. SqlClient. SqlConnection. ValidateConnectionForExecute (metodo String, SqlCommand di comando) a System. Data. SqlClient. SqlCommand. ValidateCommand (metodo String, booleano asincrona) a System. Data. SqlClient. SqlCommand. RunExecuteReader (cmdBehavior CommandBehavior, runBehavior runBehavior, returnStream booleano, il metodo String, risultato DbAsyncResult) a System. Data. SqlClient. SqlCommand. RunExecuteReader (cmdBehavior CommandBehavior, runBehavior runBehavior, returnStream booleano, String metodo) a System. Data. SqlClient. SqlCommand. ExecuteScalar () in PetaPoco. Database. Insert (String tableName, String primaryKeyName, booleano autoIncrement, oggetto poco) in C: DevCodeAPIModelsPetaPoco. cs: linea 1243 InnerException: chiesto 1 marzo 12 alle 6 : 32 Ecco una spiegazione eccellente perché è sollevato questa eccezione: la conclusione è la seguente: perché il SqlDataReader mantiene il flusso di memoria (di risultati) disponibile finché non si chiude in modo esplicito il SqlDataReader è possibile ottenere questa eccezione, se si tenta di creare un nuovo lettore senza chiudendo la precedente. Modificare il codice per avere un'istruzione using ogni volta che si crea un SqlDataReader: Utilizzando chiamerà automaticamente smaltire () (che chiude il lettore), quando la chiusura (fine) è raggiunto. Se questa eccezione è sollevata in petaPOCO poi c'è un bug nel loro codice o si utilizza il codice in un way. Whats non specificati il ​​modo migliore per ricevere il conteggio totale fila di un iTable acquisita attraverso la riflessione Poiché la riflessione viene utilizzato, System. Query Count () non è disponibile. Il pensiero successivo è quello di usare ExecuteQueryltTgt (stringa, oggetto). Un tentativo di chiamare DataContext. ExecuteQueryltintgt (quotSELECT COUNT () da SomeTablequot) produce un errore: MessagequotGenericArguments0, System. Int32, il System. Data. DLinq. Model. FieldAccessor2T, V viola il vincolo di tipo T. quot Il pensiero successivo è che forse DataContext. ExecuteCommand (stringa) potrebbe essere chiamato se esiste un modo per impostare ROWCOUNT al conte (). Ma a quanto pare T-SQL doesnt consentire tale male. Il pensiero successivo è quello di creare un IDbCommand e IDataReader da DataContext. Connection. Questo approccio è illustrato nella metodo CalculateSegmentTotal () mostrato di seguito. Il metodo solleva un InvalidOperationException dicendo, quotThere è già un DataReader aperto associato con questo comando che deve essere chiuso first. quot. A volte l'eccezione non viene inizialmente sollevato permettendo CalculateSegmentTotal () di essere chiamato una volta. Sulla seconda chiamata a CalculateSegmentTotal () l'eccezione aperto DataReader viene generata. Si noti, che in questo caso, CalculateSegmentTotal () chiede esplicitamente IDataReader. Close () e tuttavia la expception è sollevata seconda volta. Questo make mi domando: è DataContext. Connection semplicemente non significava per il pubblico di utilizzare un altro approccio potrebbe essere quello di creare una connessione di database separato per eseguire il DataReader, ma che sembra tutt'altro che ideali. Qualsiasi pensieri Grazie in anticipo, System. InvalidOperationException è stata gestita MessagequotThere è già un DataReader aperto associato con questo comando che deve essere chiuso first. quot SourcequotSystem. Dataquot StackTrace: a System. Data. SqlClient. SqlInternalConnectionTds. ValidateConnectionForExecute (SqlCommand di comando) al sistema. Data. SqlClient. SqlConnection. ValidateConnectionForExecute (metodo String, SqlCommand di comando) a System. Data. SqlClient. SqlCommand. ValidateCommand (metodo String, asincrono booleano) a System. Data. SqlClient. SqlCommand. RunExecuteReader (cmdBehavior CommandBehavior, runBehavior runBehavior, returnStream booleano , il metodo String, risultato DbAsyncResult) a System. Data. SqlClient. SqlCommand. RunExecuteReader (cmdBehavior CommandBehavior, runBehavior runBehavior, al sistema returnStream booleano, il metodo String) a System. Data. SqlClient. SqlCommand. ExecuteReader (comportamento CommandBehavior, il metodo String). Data. SqlClient. SqlCommand. ExecuteDbDataReader (comportamento CommandBehavior) a System. Datamon. DbCommand. System. Data. IDbCommand. ExecuteReader () in Trtiya. Controls. DLinq. TablePanel. CalculateSegmentTotal () in C: ProjectsDLinqDataContextEditorExampleTrtiya. ControlsDLinqTablePanel. xaml. cs: linea 104 a Trtiya. Controls. DLinq. TablePanel. setTableData (valore TableData) in C: ProjectsDLinqDataContextEditorExampleTrtiya. ControlsDLinqTablePanel. xaml. cs: linea 56 a Trtiya. Controls. DLinq. DataContextPage. mcbTablesSelectionChanged (object sender, SelectionChangedEventArgs e) in C: ProjectsDLinqDataContextEditorExampleTrtiya. ControlsDLinqDataContextPage. xaml. cs: linea 82 a System. Windows. Controls. SelectionChangedEventArgs. InvokeEventHandler (Delegato GenericHandler, Object genericTarget) a System. Windows. RoutedEventArgs. InvokeHandler (gestore delegato, Object target) a System. Windows. RoutedEventHandlerInfo. InvokeHandler ( Object target, RoutedEventArgs RoutedEventArgs) a System. Windows. EventRoute. InvokeHandlersImpl (fonte Object, RoutedEventArgs args, booleano rilanciato) a System. Windows. UIElement. RaiseEventImpl (RoutedEventArgs args) a System. Windows. UIElement. RaiseEvent (RoutedEventArgs e) al sistema. Windows. ControlsboBox. OnSelectionChanged (SelectionChangedEventArgs e) in System. Windows. Controls. Primitives. Selector. SelectionChanger. End () in System. Windows. Controls. Primitives. Selector. SelectionChanger. SelectJustThisItem (voce Object, booleano assumeInItemsCollection) al sistema. Windows. ControlsboBoxItem. OnMouseLeftButtonUp (MouseButtonEventArgs e) in System. Windows. UIElement. OnMouseLeftButtonUpThunk (object sender, MouseButtonEventArgs e) in System. Windows. Input. MouseButtonEventArgs. InvokeEventHandler (Delegato GenericHandler, Object genericTarget) a System. Windows. RoutedEventArgs. InvokeHandler ( delegato del gestore, Object target) a System. Windows. RoutedEventHandlerInfo. InvokeHandler (target Object, RoutedEventArgs RoutedEventArgs) a System. Windows. EventRoute. InvokeHandlersImpl (fonte Object, RoutedEventArgs args, booleano rilanciato) a System. Windows. UIElement. ReRaiseEventAs (RoutedEventArgs args , RoutedEvent NewEvent) a System. Windows. UIElement. OnMouseUpThunk (object sender, MouseButtonEventArgs e) in System. Windows. Input. MouseButtonEventArgs. InvokeEventHandler (Delegato GenericHandler, Object genericTarget) a System. Windows. RoutedEventArgs. InvokeHandler (gestore delegato, Object target ) a System. Windows. RoutedEventHandlerInfo. InvokeHandler (target Object, RoutedEventArgs RoutedEventArgs) a System. Windows. EventRoute. InvokeHandlersImpl (fonte Object, RoutedEventArgs args, booleano rilanciato) a System. Windows. UIElement. RaiseEventImpl (RoutedEventArgs args) a System. Windows. UIElement. RaiseEvent (RoutedEventArgs args, booleano trusted) a System. Windows. Input. InputManager. ProcessStagingArea () in System. Windows. Input. InputManager. ProcessInput (ingresso InputEventArgs) a System. Windows. Input. InputProviderSite. ReportInput (InputReport inputReport ) a System. Windows. Interop. HwndMouseInputProvider. ReportInput (IntPtr hwnd, modalità InputMode, Int32 timestamp, azioni RawMouseActions, Int32 x, y Int32, ruota Int32) a System. Windows. Interop. HwndMouseInputProvider. FilterMessage (IntPtr hwnd, Int32 msg, IntPtr wParam, lParam IntPtr, Booleanamp gestito) in System. Windows. Interop. HwndSource. InputFilterMessage (IntPtr hwnd, Int32 msg, IntPtr wParam, lParam IntPtr, Booleanamp gestito) in MS. Win32.HwndWrapper. WndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, lParam IntPtr, Booleanamp gestito) in MS. Win32.HwndSubclass. DispatcherCallbackOperation (Object o) a System. Windows. Threading. ExceptionWrapper. InternalRealCall (Delegato di callback, oggetto args, booleano isSingleParameter) a System. Windows. Threading. ExceptionWrapper. TryCatchWhen (fonte Object, Delegato di callback, args Object, booleano isSingleParameter, Delegato catchHandler) a System. Windows. Threading. Dispatcher. InvokeImpl (priorità DispatcherPriority, TimeSpan timeout, metodo delegato, oggetto args, booleano isSingleParameter) a System. Windows. Threading. Dispatcher. Invoke (priorità DispatcherPriority, metodo delegato, Object arg) a MS. Win32.HwndSubclass. SubclassWndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, lParam IntPtr) a MS. Win32.UnsafeNativeMethods. DispatchMessage (MSGamp msg) a System. Windows. Threading. Dispatcher. PushFrameImpl (cornice DispatcherFrame) a System. Windows. Threading. Dispatcher. PushFrame (fotogramma DispatcherFrame) a System. Windows. Threading. Dispatcher. Run () in System. Windows. Application. RunInternal (finestra window) al sistema. Windows. Application. Run (finestra finestra) a System. Windows. Application. Run () in DLinqDataContextEditorExample. MyApp. Main () in C: ProjectsDLinqDataContextEditorExampleDLinqDataContextEditorExampleobjDebugMyApp. g.cs: linea 50 a System. AppDomain. nExecuteAssembly (assemblaggio assembly, String args) in corrispondenza di System. Threading. ExecutionContext. Run System. AppDomain. ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String args) a Microsoft. VisualStudio. HostingProcess. HostProc. RunUsersAssembly () in System. Threading. ThreadHelper. ThreadStartContext (stato Object) (ExecutionContext ExecutionContext, ContextCallback richiamata, oggetto di stato) a System. Threading. ThreadHelper. ThreadStart () collegamento IDbConnection mTableData. Tavolo. Contesto. Collegamento ConnectionState priorConnectionState. Stato IDataReader dataReader nullo int nRowCount 0 collegamento IDbCommand cmdCount. CreateCommand () Se ho capito la tua situazione, youve recuperata una tabella da un DataContext, ma non si sa esattamente quale. Si desidera recuperare il conteggio delle righe da esso. Heres un sonno-privato modo per andare a prendere un iTable (un QueryltTgt, in realtà), utilizzando la riflessione per ottenere il CountltTgt corretta, e invocando esso (si noti l'uso gratuito di LINQ per fare la scansione metodo): Mercoledì 8 Marzo 2006 09:46 Tutte le risposte Se ho capito la tua situazione, youve recuperate una tabella da un DataContext, ma non si sa esattamente quale. Si desidera recuperare il conteggio delle righe da esso. Heres un sonno-privato modo per andare a prendere un iTable (un QueryltTgt, in realtà), utilizzando la riflessione per ottenere il CountltTgt corretta, e invocando esso (si noti l'uso gratuito di LINQ per fare la scansione metodo): Mercoledì 8 Marzo 2006 09:46

No comments:

Post a Comment