Visualizzazione dei risultati da 1 a 8 su 8

Discussione: problema con access

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    118

    problema con access

    avete presente il file di access che si crea quando accedete al suddetto database ?
    bene. esempio: avvio un applicazione in locale che prevede un accesso ad un data base access per riempire un DataGrid ,se cambio pagina ed eseguo un'altra applicazione che accede allo stesso data base mi viene negato l'accesso.
    Faccio presente che le connessioni vengono sempre chiuse.
    Anche se chiudo il browser o 'stoppo' e riavvio IIS quel file rimane
    e non è possibile eliminarlo.
    Non lo si trova neanche tra i file in esecuzione dal Task Manager.
    Cosa ho fatto che non gli piace ?
    grazie.
    D.T.K.L.A.M.F.

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    4,127
    posta il codice

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    118
    il codice è preso da un testo sul quale sto facendo delle preve.
    Anche riutilizza ndo il codice originario ,che ti posto,mi rimane la connessione attiva ,almeno credo.
    grazie
    ciao.
    <%@ Page Language="VB" Debug="true" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

    <script runat="server" >
    'declare connection
    dim Conn as new OleDbConnection( _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\inetpub\wwwroot\nome_database.mdb")

    sub Page_Load(obj as Object, e as EventArgs)
    if Not Page.IsPostBack then
    FillDataGrid()
    end if
    end sub

    sub Submit(obj as object, e as eventargs)
    'insert new data
    dim i, j as integer
    dim params(7) as string
    dim strText as string
    dim blnGo as boolean = true

    j = 0

    for i = 0 to AddPanel.Controls.Count - 1
    if AddPanel.controls(i).GetType Is GetType(TextBox) then
    strText = Ctype(AddPanel.Controls(i), TextBox).Text
    if strText <> "" then
    params(j) = strText
    else
    blnGo = false
    lblMessage.Text = lblMessage.Text & "You forgot to enter " & _
    "a value for " & AddPanel.Controls(i).ID & "

    "
    lblMessage.Style("ForeColor") = "Red"
    end if
    j = j + 1
    end if
    next

    for i = 0 to AddPanel.Controls.Count - 1
    if AddPanel.controls(i).GetType Is GetType(TextBox) then
    Ctype(AddPanel.Controls(i), TextBox).Text = ""
    end if
    next

    if not blnGo then
    exit sub
    end if

    dim strSQL as string = "INSERT INTO tblUsers " & _
    "(FirstName, LastName, Address, City, State, " & _
    "Zip, Phone) VALUES (" & _
    "'" & params(0) & "'," & _
    "'" & params(1) & "'," & _
    "'" & params(2) & "'," & _
    "'" & params(3) & "'," & _
    "'" & params(4) & "'," & _
    "'" & params(5) & "'," & _
    "'" & params(6) & "')"

    ExecuteStatement(strSQL)

    FillDataGrid()
    end sub

    sub dgData_Edit(obj as object, e as DataGridCommandEventArgs)
    FillDataGrid(e.Item.ItemIndex)
    end sub

    sub dgData_Delete(obj as object, e as DataGridCommandEventArgs)
    dim strSQL as string = "DELETE * FROM tblUsers " & _
    "WHERE User_ID = " & Ctype(e.Item.Cells(0).Controls(1), Label).text

    ' se si vuole fare riferimento fisicamente alla posizione dell'item nella lista
    ' "WHERE User_ID = " & e.Item.ItemIndex + 1
    '
    ExecuteStatement(strSQL)
    FillDataGrid()
    end sub

    sub dgData_Update(obj as object, e as DataGridCommandEventArgs)
    if UpdateDataStore(e) then
    FillDataGrid(-1)
    end if
    end sub

    sub dgData_Cancel(obj as object, e as DataGridCommandEventArgs)
    FillDataGrid(-1)
    end sub

    sub dgData_PageIndexChanged(obj as Object, e as DataGridPageChangedEventArgs)
    dgData.DataBind()
    end sub

    function UpdateDataStore(e as DataGridCommandEventArgs) _
    as boolean

    dim i,j as integer
    dim params(7) as string
    dim strText as string
    dim blnGo as boolean = true

    j = 0

    for i = 1 to e.Item.Cells.Count - 3
    strText = Ctype(e.Item.Cells(i).Controls(0), TextBox).Text
    if strText <> "" then
    params(j) = strText
    j = j + 1
    else
    blnGo = false
    lblMessage.Text = lblMessage.Text & "You forgot to enter " & _
    "a value

    "
    end if
    next

    if not blnGo then
    return false
    exit function
    end if

    dim strSQL as string = "UPDATE tblUsers SET " & _
    "FirstName = '" & params(0) & "'," & _
    "LastName = '" & params(1) & "'," & _
    "Address = '" & params(2) & "'," & _
    "City = '" & params(3) & "'," & _
    "State = '" & params(4) & "'," & _
    "Zip = '" & params(5) & "'," & _
    "Phone = '" & params(6) & "'" & _
    " WHERE User_ID = " & Ctype(e.Item.Cells(0).Controls(1), Label).text

    ExecuteStatement(strSQL)
    return blnGo
    end function

    sub FillDataGrid(Optional EditIndex as integer=-1)
    'open connection
    dim objCmd as new OleDbCommand _
    ("select * from tblUsers", Conn)
    dim objReader as OleDbDataReader

    try
    objCmd.Connection.Open()
    objReader = objCmd.ExecuteReader()
    catch ex as Exception
    lblMessage.Text = "Error retrieving from the database. Please" & _
    " make sure all values are correctly input"
    end try

    dgData.DataSource = objReader
    if not EditIndex.Equals(Nothing) then
    dgData.EditItemIndex = EditIndex
    end if

    dgData.DataBind()

    objReader.Close
    objCmd.Connection.Close()

    end sub

    function ExecuteStatement(strSQL)
    dim objCmd as new OleDbCommand(strSQL, Conn)

    try
    objCmd.Connection.Open()
    objCmd.ExecuteNonQuery()
    catch ex as Exception
    lblMessage.Text = "Error updating the database. Please" & _
    " make sure all values are correctly input"
    end try

    objCmd.Connection.Close()
    end function
    </script>

    <html><body>
    <asp:Label id="lblMessage" runat="server"/>

    <form runat="server">
    <aspataGrid id="dgData" runat="server"


    font-names="arial"
    font-size="12pt"
    showfooter="true"
    headerStyle-backcolor="#ff3311"
    footerstyle-backcolor="#ff3311"
    itemstyle-backcolor="lightblue"
    alternatingItemStyle-backcolor="#dddddd"


    BorderColor="red" GridLines="Vertical"
    cellpadding="2"
    cellspacing="0"
    width="100%"
    AutoGenerateColumns="False"
    OnDeleteCommand="dgData_Delete"
    OnEditCommand="dgData_Edit"
    OnCancelCommand="dgData_Cancel"
    OnUpdateCommand="dgData_Update"
    OnPageIndexChanged="dgData_PageIndexChanged" >

    <Columns>
    <asp:TemplateColumn HeaderText="ID">
    <ItemTemplate>
    <asp:Label id="Name" runat="server"
    Text='<%# Container.DataItem("UserID") %>'/>
    </ItemTemplate>

    </asp:TemplateColumn>

    <asp:BoundColumn HeaderText="FirstName" DataField="FirstName" />
    <asp:BoundColumn HeaderText="LastName" DataField="LastName" />
    <asp:BoundColumn HeaderText="Address" DataField="Address" />
    <asp:BoundColumn HeaderText="City" DataField="City"/>
    <asp:BoundColumn HeaderText="State" DataField="State" />
    <asp:BoundColumn HeaderText="Zip" DataField="Zip" />
    <asp:BoundColumn HeaderText="Phone" DataField="Phone"/>

    <asp:EditCommandColumn
    EditText="Edit"
    CancelText="Cancel"
    UpdateText="Update"
    HeaderText="Edit"/>

    <asp:ButtonColumn HeaderText="" text="Delete"
    CommandName="delete" />
    </Columns>
    </aspataGrid>



    <asp:Panel id="AddPanel" runat="server">
    <table>
    <tr>
    <td width="100" valign="top">
    First and last name:
    </td>
    <td width="300" valign="top">
    <asp:TextBox id="tbFName" runat="server"/>
    <asp:TextBox id="tbLName" runat="server"/>
    </td>
    </tr>
    <tr>
    <td valign="top">
    Address:
    </td>
    <td valign="top">
    <asp:TextBox id="tbAddress"
    runat="server" />
    </td>
    </tr>
    <tr>
    <td valign="top">
    City, State, ZIP:
    </td>
    <td valign="top">
    <asp:TextBox id="tbCity"
    runat="server" />,
    <asp:TextBox id="tbState" runat="server"
    size=2 />
    <asp:TextBox id="tbZIP" runat="server"
    size=5 />
    </td>
    </tr>
    <tr>
    <td valign="top">
    Phone:
    </td>
    <td valign="top">
    <asp:TextBox id="tbPhone" runat="server"
    size=11 />


    </td>
    </tr>
    <tr>
    <td colspan="2" valign="top" align="right">
    <asp:Button id="btSubmit" runat="server"
    text="Add"
    OnClick="Submit" />
    </td>
    </tr>
    </table>
    </asp:Panel>
    </form>
    </body></html>
    D.T.K.L.A.M.F.

  4. #4
    1) prova a chiudere visual studio e usare per le prove il solo browser

    2) controlla i permessi di cartella e file di access (può essere che inavvertitamente gli hai messo il controllo esclusivo)
    Quindi tasto destro sulla cartella che contiene il db e estendi le proprietà a tutti, controlla anche tasto dx sul file access

    99 % il problema sta al punto 2
    Frate Priore: "È Lucifero in persona!"
    Trinità: "Lo conosci?"
    Bambino: "Mai sentito nominare, deve essere un professionista dell'est"

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    118
    grazie per i suggerimenti.
    comunque non si trattava di nulla del genere.


    Quando faccio delle prove non uso il visualstudio ma lavoro direttamente su un file di testo notepad nella root.(lavoro in locale)
    Sono amministratore della macchina ed ho tutti i permessi.
    (ho controllato)
    Ho ricontrollato tutte le impostazioni di IIS.

    Ho dovuto reinstallare access.
    Ora va tutto bene.
    Se riuscirò a scoprire il vero motivo te lo farò sapere,così ,giusto per informazione personale.

    Di nuovo grazie.
    ciao
    D.T.K.L.A.M.F.

  6. #6
    Ho dovuto reinstallare access
    sono contento, ma mi permetto di insistere, credo sia problemi di permessi con access

    avendolo reistallato e aperto il file, ora questo è di proprietà della macchina (o dell'utente)...

    in ogni caso bene così
    Frate Priore: "È Lucifero in persona!"
    Trinità: "Lo conosci?"
    Bambino: "Mai sentito nominare, deve essere un professionista dell'est"

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    118
    si ti permetto di insistere ma solo perchè sei della mia stessa città di nascita.

    ciao.
    p.s. i permessi li avevo controllati............
    D.T.K.L.A.M.F.

  8. #8
    si ti permetto di insistere ma solo perchè sei della mia stessa città di nascita
    ahh bhè allora ...
    Frate Priore: "È Lucifero in persona!"
    Trinità: "Lo conosci?"
    Bambino: "Mai sentito nominare, deve essere un professionista dell'est"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.