How can I connect to an Access DB from a webfarm?

Last post 02-21-2007 2:01 PM by Knoter. 1 replies.

Sort Posts:

  • How can I connect to an Access DB from a webfarm?

    02-21-2007, 12:37 PM
    • Loading...
    • Knoter
    • Joined on 02-19-2007, 11:51 AM
    • Posts 8
    Scenario:
    I've a WebFarm with 2 web servers which are NLBs (network load balanced).
    Web1 and Web2; they are not part of a domain.
    I have a third server, Server3, which is part of a domain and on the same physical network, and it has an MSAccess database which is used on the external webfarm as well as on the internal intranet. I can connect via the intranet because the DB file is on the same box from which the intranet is being served (Server3)

    How can I 'connect' to the MSAccess database file on Server3 from either Web1 or Web2?

    When I use the code below, I get this error:
    The Microsoft Jet database engine cannot open the file '\\Server3\C$\MSAccessDBs\Database.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

    Any clues?

    Here's more info:

    I'm using ASP.NET v1.1, using a standard OLEDb connection (referencing the database by path [see code below]).

    From the ASP.NET v1.1 "web.config" file (I'll refer to this as ConnectStringA) 
    1     <appSettings>
    2        <add key="strConnectAccess" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Server3\MSAccess\DatabaseFile.mdb"/>
    3    </appSettings>
    


    actual "connect" code:
    ... I'm pausing here.
    I went to go look at the connection code and there is a direct inline connection string to another database which ap[ears to not be failing:
    \\Server3\C$\MSAccess\LogError.mdb
    --> I'll refer to this as ConnectStringB,

    The difference between ConnectStringA and ConnectStringB is that ConnectStringA assumes a shared folder, whereas ConnectStringB goes direct, as it includes the "\C$" element.

    Well, I added the "\C$" to ConnectStringA, (now "\Server3\C$\MSAccess\DatabaseFile.mdb") and it still fails.

    Yes, I would agree there is some sort of permissions error.  The database is set for Shared.

    Here is my "connect" code (modified to protect a client's database)

    1        Sub btnlogin_click(ByVal sender As Object, ByVal e As EventArgs)
    2            Dim conpw As OleDb.OleDbConnection
    3            Dim cmdpw As OleDb.OleDbCommand
    4            Dim strsql As String
    5    
    6            Dim dappw As OleDb.OleDbDataAdapter
    7            Dim dstpw As DataSet
    8            Dim rowpw As DataRow
    9            Dim bldpw As OleDb.OleDbCommandBuilder
    10           Dim inti As Integer
    11           Dim rdrpw As OleDb.OleDbDataReader
    12   
    13           Dim xx As String
    14           Dim yy As String
    15           Dim strmsg As String
    16           Dim strcounties As String
    17           Dim lngposition As Long
    18           Dim strIsCSR As String
    19   
    20           If txtIsCSR.Checked = "True" Then
    21               Session.Contents("IsUser2") = "True"
    22               Session.Contents("userName2") = txtUserName.Value
    23               Session.Contents("userPass2") = txtPassword.Value
    24               Response.Redirect("user2Logon.aspx")
    25           End If
    26   
    27           lngposition = InStr(txtPassword.Value, "'")
    28           If lngposition > 0 Then
    29               Response.Redirect("loginError.aspx")
    30           End If
    31   
    32   
    33           conpw = New OleDb.OleDbConnection(ConfigurationSettings.AppSettings("strConnectAccess"))
    34           conpw.Open()
    35   
    36   
    37           strsql = "SELECT * " & _
    38           "FROM [ User] " & _
    39           " WHERE ( ([ User]].UserName = '" & txtUserName.Value & "') AND ([ User].password = '" & txtPassword.Value & "') )  "
    40   
    41           cmdpw = New OleDb.OleDbCommand(strsql, conpw)
    42           rdrpw = cmdpw.executereader
    43   
    44           xx = 0
    45           While rdrpw.read
    46               xx = xx + 1
    47               strmsg = rdrpw.item("userID") + rdrpw.item("userName")
    48               strcounties = strcounties + strmsg
    49           End While
    50   
    51           conpw.close()
    52   
    53           If xx > 0 Then
    54               Session.Contents("counties") = txtMemberid.Value
    55               Response.Redirect("Here.aspx")
    56           Else
    57               If Len(Trim(Session.Contents("logintrys"))) = 0 Then
    58                   Session.Contents("logintrys") = 0
    59               End If
    60               ctry = (Session.Contents("logintrys"))
    61               ltrys = CInt(ctry) + 1
    62               If ltrys > 6 Then
    63                   Response.Redirect("lockout.aspx")
    64               End If
    65               ctry = CStr(ltrys)
    66               Session.Contents("logintrys") = ctry
    67               Response.Redirect("loginError.aspx")
    68           End If
    69   
    70       End Sub
    

    So, in all, this error [below] is occuring, it does point to "permissions" of some kind, I think.  the Database is not set to exclusive. "Everyone" and "guest" have "Read/Write" to all files in folder (yes, a security hole). 

    The Microsoft Jet database engine cannot open the file '\\Server3\C$\MSAccessDBs\Database.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

    Thing is, how to I "connect" from a webfarm not on a domain to a server (Server3) which is on a domain?

  • Re: How can I connect to an Access DB from a webfarm?

    02-21-2007, 2:01 PM
    • Loading...
    • Knoter
    • Joined on 02-19-2007, 11:51 AM
    • Posts 8

    FYI ~ I have set all 3 servers up with the same username/password (used by IIS). The user account on Server3 has full control to the folder and file.

    I did create a page on Web1 and Web2 that accesses an image  in the same directory on Server3 (for display on a web page), and the image displays fine.

    I did visit Microsoft's website and read through several KB articles, but no success; #253580, #315276 (NTRights Utlitity)

    The NTRights utility (KB #315276) adds permissions from ServerA to access content on ServerB.

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter