This is really weird, I can't get a grip around it. I have a SqlDataSource linked with a datagrid. All works well, that is until I try to rebind the SqlDataSource. Then I get the following error:
Login failed for user 'testuser'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'testuser'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Login failed for user 'testuser'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4890855
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2412
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject, Boolean withFailover) +247
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +1349
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +225
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +431
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +31
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +112
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1297
System.Web.UI.WebControls.BaseDataList.GetData() +38
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +153
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +54
System.Web.UI.WebControls.BaseDataList.DataBind() +55
System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +60
System.Web.UI.WebControls.BaseDataList.OnPreRender(EventArgs e) +15
System.Web.UI.Control.PreRenderRecursiveInternal() +80
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
I'm looking at this already for a few hours and just can't find it. When debugging, no exception is raised, but I see in the SQL profiler that the query isn't even fired.
So what happens is that the page gets loaded and the datagrid gets populated. Then by clicking on a link, the code behind gets fired, executes a sub in which I call the function again to populated the list (with updated values this time). Here, I get a page with the error from above.
This is the sub I'm using:
Sub UpdateInvoiceListNoEvent()
'Dim CmdBatch As New SqlCommand
Dim InvoiceSent As Integer = 0
Dim InvoiceReady As String = " "
Dim InvoiceSuccess As Integer = 0
Dim InvoiceFailed As Integer = 0
Dim SelectedEntity As String = " "
Try
Data_unbatched.Dispose()
If Len(drp_entity.SelectedValue.ToString()) > 1 Then
SelectedEntity = drp_entity.SelectedValue.ToString()
End If
If chk_Ready_search.Checked Then InvoiceReady = "approved"
If chk_Failed_search.Checked Then InvoiceFailed = 2
If chk_Sent_search.Checked Then InvoiceSent = 1
If chk_Success_search.Checked Then InvoiceSuccess = 3
Data_unbatched.ConnectionString = Conn.ConnectionString
Data_unbatched.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
Data_unbatched.SelectParameters.Clear()
Data_unbatched.SelectCommand = "selectInvoices"
Data_unbatched.SelectParameters.Add("entity", " ")
Data_unbatched.SelectParameters.Add("ready", InvoiceReady)
Data_unbatched.SelectParameters.Add("sent", InvoiceSent)
Data_unbatched.SelectParameters.Add("failed", InvoiceFailed)
Data_unbatched.SelectParameters.Add("success", InvoiceSuccess)
tble_add_batch.Visible = True
grid_view_header.Visible = True
Catch sqlex As SqlException
Logger.Error(System.Reflection.MethodInfo.GetCurrentMethod.ToString + " -> " + sqlex.Message.ToString + " -> Stack trace: " + sqlex.StackTrace)
Catch ex As Exception
Logger.Error(System.Reflection.MethodInfo.GetCurrentMethod.ToString + " -> " + ex.Message.ToString + " -> Stack trace: " + ex.StackTrace)
Finally
If (Conn.State = ConnectionState.Open) Then
Conn.Close()
End If
posted = True
End Try
End Sub
I had a similar issue when I was trying to run the query with the varchar parameter set to "" while in the stored procedure it was defined as varchar(4). When I set the parameter to " " it solved it. But here, I'm completely stuck. I can leave the page like it is, but without a refresh the user will not see the updated fields, until he manually refreshes.
I'm lost and any input would be greatly appreciated.
You may need to reopen the dB Connection since you close it inside finally block first time around. If you do it during page load make sure you not skipping it with if(!Page.IsPostBack) check.
User contributions licensed under CC BY-SA 3.0