VB:重新加载SqlDataSource时,'user'登录失败

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB:重新加载SqlDataSource时,'user'登录失败相关的知识,希望对你有一定的参考价值。

这真的很奇怪,我无法控制它。我有一个与datagrid链接的SqlDataSource。一切正常,直到我尝试重新绑定SqlDataSource。然后我收到以下错误:

用户'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

我已经看了几个小时,但却找不到它。在调试时,没有引发异常,但我在SQL分析器中看到查询甚至没有被触发。

所以会发生什么是页面被加载并且数据网格被填充。然后通过单击一个链接,后面的代码被触发,执行一个sub,我再次调用该函数来填充列表(这次使用更新的值)。在这里,我得到一个包含上述错误的页面。

这是我正在使用的子项:

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

结束子

当我尝试运行varchar参数设置为“”的查询时,我遇到了类似的问题,而在存储过程中,它被定义为varchar(4)。当我将参数设置为“”时,它解决了它。但在这里,我完全陷入困境。我可以像往常一样离开页面,但是如果没有刷新,用户将无法看到更新的字段,直到他手动刷新。

我迷路了,任何意见都会非常感激。

答案

您可能需要重新打开dB连接,因为您在第一次关闭它时最终阻止它。如果在页面加载期间执行此操作,请确保不使用if(!Page.IsPostBack)检查来跳过它。

以上是关于VB:重新加载SqlDataSource时,'user'登录失败的主要内容,如果未能解决你的问题,请参考以下文章

vb.net 应用程序重新加载 INI 文件

在VB6中编译DLL时“加载DLL时出错”

ASP.NET:将外部变量传递到 <asp:sqldatasource> 标记 ASP.NET 2.0

mscomctl.ocx 加载失败!system32中有这个文件,也可以注册成功,但运行vb时 还是提示不能加载!

vb窗体中的resize是啥事件?

Telerik Reporting - 使用 SqlDataSource 时无法在 Chrome 中导出