简体   繁体   中英

ip2location always prints "Invalid Database Path" - How to call their database file?

In order to get 2 letters of country from IP Address, I was advised to use this bin database https://lite.ip2location.com/database-ip-country-region-city

But wherever I place their database file, I always get this error message:

Invalid Database Path.

I guess the error lies in this line:

oIP2Location.IPDatabasePath = "IP2LOCATION-LITE-DB1.BIN"

Here's some of the Code. How to correctly link to the path of the BIN file?

    Private Sub Query(ByVal strIPAddress As String)
    Dim oIPResult As New IP2Location.IPResult
    Dim oIP2Location As New IP2Location.Component
    Try
        If strIPAddress <> "" Then
            oIP2Location.IPDatabasePath = "IP2LOCATION-LITE-DB1.BIN" ' only IPv4

            oIPResult = oIP2Location.IPQuery(strIPAddress)
            Select Case oIPResult.Status
                Case "OK"
                    Me.txtIPResult.Text += "IP Address: " & oIPResult.IPAddress & vbNewLine
                    Me.txtIPResult.Text += "City: " & oIPResult.City & vbNewLine
                    Me.txtIPResult.Text += "Country Code: " & oIPResult.CountryShort & vbNewLine
                    Me.txtIPResult.Text += "Country Name: " & oIPResult.CountryLong & vbNewLine
                    Me.txtIPResult.Text += "Postal Code: " & oIPResult.ZipCode & vbNewLine
                    Me.txtIPResult.Text += "Domain Name: " & oIPResult.DomainName & vbNewLine
                    Me.txtIPResult.Text += "ISP Name: " & oIPResult.InternetServiceProvider & vbNewLine
                    Me.txtIPResult.Text += "Latitude: " & oIPResult.Latitude & vbNewLine
                    Me.txtIPResult.Text += "Longitude: " & oIPResult.Longitude & vbNewLine
                    Me.txtIPResult.Text += "Region: " & oIPResult.Region & vbNewLine
                    Me.txtIPResult.Text += "Time Zone: " & oIPResult.TimeZone & vbNewLine
                    Me.txtIPResult.Text += "Net Speed: " & oIPResult.NetSpeed & vbNewLine
                    Me.txtIPResult.Text += "IDD Code: " & oIPResult.IDDCode & vbNewLine
                    Me.txtIPResult.Text += "Area Code: " & oIPResult.AreaCode & vbNewLine
                    Me.txtIPResult.Text += "Weather Station Code: " & oIPResult.WeatherStationCode & vbNewLine
                    Me.txtIPResult.Text += "Weather Station Name: " & oIPResult.WeatherStationName & vbNewLine
                    Me.txtIPResult.Text += "MCC: " & oIPResult.MCC & vbNewLine
                    Me.txtIPResult.Text += "MNC: " & oIPResult.MNC & vbNewLine
                    Me.txtIPResult.Text += "Mobile Brand: " & oIPResult.MobileBrand & vbNewLine
                    Me.txtIPResult.Text += "Elevation: " & oIPResult.Elevation & vbNewLine
                    Me.txtIPResult.Text += "Usage Type: " & oIPResult.UsageType & vbNewLine
                Case "EMPTY_IP_ADDRESS"
                    Response.Write("IP Address cannot be blank.")
                Case "INVALID_IP_ADDRESS"
                    Response.Write("Invalid IP Address.")
                Case "MISSING_FILE"
                    Response.Write("Invalid Database Path.")
            End Select
        Else
            Response.Write("IP Address cannot be blank.")
        End If
    Catch ex As Exception
        Response.Write(ex.Message)
    Finally
        oIPResult = Nothing
        oIP2Location = Nothing
    End Try
End Sub

You have 2 options for specifying the path to the BIN file.

Either use the full path to the BIN file.

oIP2Location.IPDatabasePath = "c:\myfolder\mysubfolder\IP2LOCATION-LITE-DB1.BIN"

Or use the relative path to the website root folder and call MapPath to get the full path. Below example is for a BIN file inside the bin folder.

oIP2Location.IPDatabasePath = Server.MapPath("bin\IP2LOCATION-LITE-DB1.BIN")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM