locked
Closing a Access Datasource Connection RRS feed

  • Question

  • User-456111751 posted

    Hi,

    I am using a AccessDatasource for getting values from a accessdatabase for a Dropdown list. After i load the page and close it, a .ldb file is created. After wards i am not able to open the database manually. How to close the connection.

    I have given Network service Modify access (http://forums.asp.net/t/1382480.aspx) to share permission, still no go.

    Any help.

    Tuesday, July 20, 2010 4:18 AM

Answers

  • User-821857111 posted

    Double check that you have applied Modify permissions on the folder containing the Access database to the correct user account: http://www.west-wind.com/weblog/posts/2153.aspx. It varies depending on a number of factors, and may not always be NETWORK SERVICE.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 20, 2010 9:17 AM

All replies

  • User-821857111 posted

    Double check that you have applied Modify permissions on the folder containing the Access database to the correct user account: http://www.west-wind.com/weblog/posts/2153.aspx. It varies depending on a number of factors, and may not always be NETWORK SERVICE.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 20, 2010 9:17 AM
  • User-456111751 posted

    Do the database connection gets closed automatically after retrieving the data with SQLDatasource/Accessdatasource? 

    Wednesday, July 21, 2010 1:06 AM
  • User-1199946673 posted

    Do the database connection gets closed automatically after retrieving the data with SQLDatasource/Accessdatasource? 
     

    yes

    Protected Friend Overrides Function ExecuteSelect(ByVal arguments As DataSourceSelectArguments) As IEnumerable
        Dim dependency As SqlCacheDependency
        If (Me.SelectCommand.Length = 0) Then
            Return Nothing
        End If
        Dim connection As DbConnection = Me._owner.CreateConnection(Me._owner.ConnectionString)
        If (connection Is Nothing) Then
            Throw New InvalidOperationException(SR.GetString("SqlDataSourceView_CouldNotCreateConnection", New Object() { Me._owner.ID }))
        End If
        Dim cache As DataSourceCache = Me._owner.Cache
        Dim flag As Boolean = ((Not cache Is Nothing) AndAlso cache.Enabled)
        Dim sortExpression As String = arguments.SortExpression
        If Me.CanPage Then
            arguments.AddSupportedCapabilities(DataSourceCapabilities.Page)
        End If
        If Me.CanSort Then
            arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort)
        End If
        If Me.CanRetrieveTotalRowCount Then
            arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount)
        End If
        If flag Then
            If (Me._owner.DataSourceMode <> SqlDataSourceMode.DataSet) Then
                Throw New NotSupportedException(SR.GetString("SqlDataSourceView_CacheNotSupported", New Object() { Me._owner.ID }))
            End If
            arguments.RaiseUnsupportedCapabilitiesError(Me)
            Dim set As DataSet = TryCast(Me._owner.LoadDataFromCache(0, -1),DataSet)
            If (Not [set] Is Nothing) Then
                Dim parameterValues As IOrderedDictionary = Me.FilterParameters.GetValues(Me._context, Me._owner)
                If (Me.FilterExpression.Length > 0) Then
                    Dim args As New SqlDataSourceFilteringEventArgs(parameterValues)
                    Me.OnFiltering(args)
                    If args.Cancel Then
                        Return Nothing
                    End If
                End If
                Return FilteredDataSetHelper.CreateFilteredDataView([set].Tables.Item(0), sortExpression, Me.FilterExpression, parameterValues)
            End If
        End If
        Dim command As DbCommand = Me._owner.CreateCommand(Me.SelectCommand, connection)
        Me.InitializeParameters(command, Me.SelectParameters, Nothing)
        command.CommandType = SqlDataSourceView.GetCommandType(Me.SelectCommandType)
        Dim e As New SqlDataSourceSelectingEventArgs(command, arguments)
        Me.OnSelecting(e)
        If e.Cancel Then
            Return Nothing
        End If
        Dim sortParameterName As String = Me.SortParameterName
        If (sortParameterName.Length > 0) Then
            If (command.CommandType <> CommandType.StoredProcedure) Then
                Throw New NotSupportedException(SR.GetString("SqlDataSourceView_SortParameterRequiresStoredProcedure", New Object() { Me._owner.ID }))
            End If
            command.Parameters.Add(Me._owner.CreateParameter((Me.ParameterPrefix & sortParameterName), sortExpression))
            arguments.SortExpression = String.Empty
        End If
        arguments.RaiseUnsupportedCapabilitiesError(Me)
        sortExpression = arguments.SortExpression
        If Me.CancelSelectOnNullParameter Then
            Dim count As Integer = command.Parameters.Count
            Dim i As Integer
            For i = 0 To count - 1
                Dim parameter As DbParameter = command.Parameters.Item(i)
                If (((Not parameter Is Nothing) AndAlso (parameter.Value Is Nothing)) AndAlso ((parameter.Direction = ParameterDirection.Input) OrElse (parameter.Direction = ParameterDirection.InputOutput))) Then
                    Return Nothing
                End If
            Next i
        End If
        Me.ReplaceNullValues(command)
        Dim enumerable As IEnumerable = Nothing
        Select Case Me._owner.DataSourceMode
            Case SqlDataSourceMode.DataReader
                If (Me.FilterExpression.Length > 0) Then
                    Throw New NotSupportedException(SR.GetString("SqlDataSourceView_FilterNotSupported", New Object() { Me._owner.ID }))
                End If
                If (sortExpression.Length > 0) Then
                    Throw New NotSupportedException(SR.GetString("SqlDataSourceView_SortNotSupported", New Object() { Me._owner.ID }))
                End If
                Dim flag4 As Boolean = False
                Try 
                    If (connection.State <> ConnectionState.Open) Then
                        connection.Open
                    End If
                    enumerable = command.ExecuteReader(CommandBehavior.CloseConnection)
                    flag4 = True
                    Dim args6 As New SqlDataSourceStatusEventArgs(command, 0, Nothing)
                    Me.OnSelected(args6)
                Catch exception2 As Exception
                    Dim flag5 As Boolean
                    If Not flag4 Then
                        Dim args7 As New SqlDataSourceStatusEventArgs(command, 0, exception2)
                        Me.OnSelected(args7)
                        If Not args7.ExceptionHandled Then
                            Throw
                        End If
                        Return enumerable
                    End If
                    exception2 = Me.BuildCustomException(exception2, DataSourceOperation.Select, command, flag5)
                    If flag5 Then
                        Throw exception2
                    End If
                    Throw
                End Try
                Return enumerable
            Case SqlDataSourceMode.DataSet
                dependency = Nothing
                If (flag AndAlso TypeOf cache Is SqlDataSourceCache) Then
                    Dim cache2 As SqlDataSourceCache = DirectCast(cache, SqlDataSourceCache)
                    If String.Equals(cache2.SqlCacheDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase) Then
                        If Not TypeOf command Is SqlCommand Then
                            Throw New InvalidOperationException(SR.GetString("SqlDataSourceView_CommandNotificationNotSupported", New Object() { Me._owner.ID }))
                        End If
                        dependency = New SqlCacheDependency(DirectCast(command, SqlCommand))
                        Exit Select
                    End If
                End If
                Exit Select
            Case Else
                Return enumerable
        End Select
        Dim adapter As DbDataAdapter = Me._owner.CreateDataAdapter(command)
        Dim dataSet As New DataSet
        Dim affectedRows As Integer = 0
        Dim flag2 As Boolean = False
        Try 
            affectedRows = adapter.Fill(dataSet, MyBase.Name)
            flag2 = True
            Dim args3 As New SqlDataSourceStatusEventArgs(command, affectedRows, Nothing)
            Me.OnSelected(args3)
        Catch exception As Exception
            If flag2 Then
                Dim flag3 As Boolean
                exception = Me.BuildCustomException(exception, DataSourceOperation.Select, command, flag3)
                If flag3 Then
                    Throw exception
                End If
                Throw
            End If
            Dim args4 As New SqlDataSourceStatusEventArgs(command, affectedRows, exception)
            Me.OnSelected(args4)
            If Not args4.ExceptionHandled Then
                Throw
            End If
        Finally
            If (connection.State = ConnectionState.Open) Then
                connection.Close
            End If
        End Try
        Dim table As DataTable = IIf((dataSet.Tables.Count > 0), dataSet.Tables.Item(0), Nothing)
        If (flag AndAlso (Not table Is Nothing)) Then
            Me._owner.SaveDataToCache(0, -1, dataSet, dependency)
        End If
        If (table Is Nothing) Then
            Return enumerable
        End If
        Dim values As IOrderedDictionary = Me.FilterParameters.GetValues(Me._context, Me._owner)
        If (Me.FilterExpression.Length > 0) Then
            Dim args5 As New SqlDataSourceFilteringEventArgs(values)
            Me.OnFiltering(args5)
            If args5.Cancel Then
                Return Nothing
            End If
        End If
        Return FilteredDataSetHelper.CreateFilteredDataView(table, sortExpression, Me.FilterExpression, values)
    End Function
    
     
    
     
    


     

    Wednesday, July 21, 2010 4:53 AM