Connection to Database

Discussion in 'Visual Studio' started by George1111, Sep 16, 2012.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. The following Code is supposed to connect to an Internet Database (However it doesnt work when I try to connect to my own website database - I used the IP Address by running Ping ..... website name ... to get the IP address.
    Is there something else I need to do ?

    I would have thought that to connect to a DiscountASP hosted website, I may need more authentication data (as per FTP)

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    
    
     
        Dim gConn As ADODB.Connection
        Dim gCmd As ADODB.Command
        Dim gRS As ADODB.Recordset
    
        Dim strSQL As String
    
    
        Set gConn = New ADODB.Connection
        Set gCmd = New ADODB.Command
    
    
        If gConn.State = adStateClosed Then
    
            With gConn
                ' Establish DSN-less connection
                .ConnectionTimeout = 30
                .CursorLocation = adUseClient
                .Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & "\\96.33.33.33\MyDir\MYDB.mdb;" & _
                        "User Id=;" & _
                        "Password="
            End With
        End If
        
        gCmd.ActiveConnection = gConn
        gCmd.CommandText = "SELECT * FROM Members"
        Set gRS = gCmd.Execute
        MsgBox gRS.RecordCount  ' Should be 91 records
        gRS.Close
        gConn.Close
        Set gRS = Nothing
        Set gCmd = Nothing
        Set gConn = Nothing
     
    End Sub
    Can someone point me to a similar project in VB.Net to achieve the same result (I am lead to believe that the access time will be a lot faster - is that right ?


    Thanks very much for any help
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

  3. MS Access from discountasp.net to a desktop app

    I have no problem connecting to the SQL Server connection to the discountasp.net SQL server. However, I now have a need to connect to an MS Access database that is found in my website's _database folder.

    This is for a desktop application.

    How do I do either: 1) Create an MS Access DSN that points to the disccountasp.net location or 2) Utilize OLEDB to accomplish the same thing?

    It is definitely the connection string that I need help with.

    Thanks in advance,
    Jerry Scannell
     
  4. Access (.MDB) Database Connection

    Hi

    Like PGScannell, I am trying to connect to a Web Stored Database (MDB) NOT SQL SERVER, from a desktop application

    I am using VB6 but am just as happy using VB.Net if necessary

    Need
    a) Connection Address (to my database - I will also load into _Database)
    b) How to Connect
    c) How to query
    d) How to update

    Thanks
     
  5. Since no DASP staff member is pitching in here, I'm going to stick my neck out and say no, it's not going to be possible to connect directly to an access database hosted on a DASP web server over the internet from a remote desktop client application.

    The reason I say this is because this type of connection implies that a direct network path needs to be open to the location of the mdb / accdb file in the file system on the web server. We're not talking about port 80 / port 443 to the web server here - this type of connection requires an accessible file share which typically runs over a number of IP ports including 137,138,139 and 445.

    I believe the connection string in the first post in this thread that looks like \\ipaddress\folder\accessdb.mdb is the right connection string and would indeed actually work if the right ports were opened in the firewall on the DASP side to enable direct file system access to the web server. This theory is backed up by the OLEDB.4.0 Network Location connection string documented here: http://www.connectionstrings.com/access

    It's probably fair to say that DASP are never going to open the required IP ports that would enable direct file system access to the DASP web server..ever.

    That said if you really really want to use an access database, it will definitely be accessible and usable from a web application running on the DASP web server.
     
  6. Connection to database from Desktop Application

    OK - lets abandon the idea of connecting to an MDB from the desktop.

    What about connecting to SQL Server FROM THE DESKTOP -

    What are my options

    VB6 - ADO ?
    VB.Net - ADO.Net ?

    Is there a definitive example which will point me in the right direction ?

    Thanks
     
  7. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    For SQL Server, you setup a connection string just as you would a web application. It's the same. The ports for making a database connection are open.

    Regarding MS Access, yes, you will not be able to connect to it from a desktop application. The only work around I can think of is to use WEBDAV, but it's going to be very, very slow.
     
  8. Connection to SQL Server

    There have been many thousands of programmers connecting to SQL Server on DiscountASP (I should think)

    There are always traps that take hours to sort out when you have never done this before

    I am sorry, but a general comment is totally useless to me (means nothing to me as I am a coder of Desktop applications - yes - and including SQL Server on a network - I am not a Web Programmer )

    "For SQL Server, you setup a connection string just as you would a web application. It's the same. The ports for making a database connection are open" HUH ???

    What would be really nice is a simple bit of code to connect to an SQL database on DiscountASP

    1) Connect to SQL Server in my _Database Directory on DiscountASP
    2) Open the database
    3) Select a table and bunch of records

    About 20-30 lines of code - thats all

    I am sure DiscountASP even has a sample database to test things with - Yes / No?

    It would be really really helpful if the code actually works

    Appreciate any help, thanks
     
  9. mjp

    mjp

    Our first reply linked to sample code:
    Perhaps someone will offer up their own specific working code for a desktop application for you to copy, but you may not want to wait for that. Most of our users are web developers, desktop app developers are much less common.
     
  10. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Actually, that Knowledge Base article was for Microsoft Access, but we do have other sample code:

    http://support.discountasp.net/KB/a...tabase-with-net-sql-data-provider-aspnet.aspx

    We have a repository of sample code you can take a look at:

    http://support.discountasp.net/KB/c351/sample-code.aspx

    I'm afraid we don't have specific sample code for desktop applications, but the idea is the same. You might want to take a look at this link:

    http://stackoverflow.com/questions/...on-and-query-to-a-sql-server-express-database
     
  11. Access MDB Example

    The example suggested I look at was

    Code:
    <%
     Dim cnnSimple  ' ADO connection
     Dim rstSimple  ' ADO recordset
     Set cnnSimple = Server.CreateObject("ADODB.Connection")
     
    ' DSNLess
     cnnSimple.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\test.mdb"))
     
    Set rstSimple = cnnSimple.Execute("SELECT * FROM tbltest")
     %>
     
    <P> Connecting to Access with Ole connection </P>
     <table border="1">
     
    <%
     Do While Not rstSimple.EOF
     %>
     
     <tr>
       <td><%= rstSimple.Fields(0).Value %></td>
       <td><%= rstSimple.Fields(1).Value %></td>
      </tr>
     
    <%
     rstSimple.MoveNext
     Loop
     %>
     
    </table>
     
    <%
     rstSimple.Close
     Set rstSimple = Nothing
     cnnSimple.Close
     Set cnnSimple = Nothing
     %>
    I presume I just copy this code into a file called something.asp and execute it through a weblink.




    In the Code there is a connection pointing to Server.MapPath

    What would you put in this ?

    The database I understand needs to go into my _Database Folder
    My Website has a name eg, www.mywbsite.com.au

    So what goes into Server.MapPath

    These, unfortunately are such basic, basic questions.

    What is the value in Server.MapPath (IT DOES NOT HELP ME TO JUST SAY YOU NEED A SERVER.MAPPATH)

    Where is this set up - Is it in My Code, Is it in my Website configuratrion ?

    WHERE WHERE WHERE

    Eg, If it was on my server in my office (NOT IN A WEBSITE) it would be something like \\Server\Databases\

    This would then let me open a string \\Server\Databases\test.mdb

    So what is the string to open a web based database, please

    Logically it must be something like ??????????????????\_Database\test.mdb

    What is the ??????????????????? value ?

    Also, does my website need configuring to allow operation of MDB databases ?

    Sorry to be a pain but unfortunately nothing works in programming until some pretty basic stuff is correct
     
  12. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Correct.

    It should because that directory is protected.

    Please see this link on how Server.MapPath works in ASP:

    http://www.w3schools.com/asp/met_mappath.asp

    If you look at the Account Info/Edit section of the Control Panel, we provide an absolute path to the directory of your hosting account.

    Nothing to configure if you're using a DSN-less connection.
     
  13. The connection in the W3 Schools link says to use

    Server.MapPath(path)

    So if I put the exact words "Server.MapPath(path)" in my ASP page it will magically know that I am hosted in DiscountAsp, what my exact internet connection details will be, it will also know my credentials, my password etc etc etc

    Gee!!!! what a wonderful thing that simply putting

    Server.MapPath(path)

    In my asp page will do for me

    You have been so helpful

    (Please dont attempt to teach anyone how to drive a car please - you will kill yourself)

    Set 1 Turn on the car
    Step 2 Put the car into some gear
    Step 3 put ypur foot on a pedal

    What pedal ?

    Oh, any pedal will do (specifics are not required in life or computer programming - generalities will do fine)

    I am not sure you have any idea what I am asking

    Can someone who has actually made a connection to an actual database please help me

    Theory will not help the question I am asking

    I think you are simply trying to exasperate me - well - you have succeeded

    You answer is TOTALLY USELESS TO ME

    WHAT IS THE VALUE IN THE SERVER PATH

    IS IT AN IP ADDRESS ?
    IS IT ?????????
    IS IT ????????

    I HAVE NO IDEA - NEITHER, IT SEEMS DO YOU
     
  14. If you're unable to follow the w3schools documentation, perhaps Microsoft's is better: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx

    There's an example how to call this method included on that page. The 'path' parameter that you pass to MapPath is dependant on the physical path you're trying to map; no-one can tell you what the value of this parameter should be because it depends on where your files actually reside on disk on the web server in your account.

    I don't expect anyone is going to solve this one for you and give you a step by step guide that fits your exact requirements because it's quite a mundane problem. Yes this is web, not desktop development but these are the problems you can expect to have to solve when you post in a web hosts' forum. That said this totally isn't rocket science and any developer worth his / her salt will be able to debug this one and work out the solution for him / herself: if you're unable to work this out just by reading the documentation, how about publishing a test page to your account that calls the MapPath method and writes method result out to the page response so you can actually see what's going on and work out the correct value for this parameter for yourself..you know just like the w3schools page that Ray suggested shows: http://www.w3schools.com/asp/met_mappath.asp

    In the past I've gone the extra mile where someone genuinely needs help around here but I only do it where the problem subject interests me. This one doesn't so I for one won't be analysing the file system structure on the web server for your account and spelling out the solution for you. If you have the application development experience that you allude to having in your prior posts then I'm sure you have the required ability here and understand that this is just like playing with lego - it's a case of just pulling small working parts together into a larger whole that makes sense for your application.

    It's not really my place to say this because I'm not a forum admin or moderator here however I feel compelled to as a parting note to advise you to try and curb your temper, keep your posts polite and generally remember your web etiquette. This is a public forum and no-one is contractually liable or obliged to help anyone else. When people do try and help, it's because they want to, not because they have to and one thing's for sure - nobody likes being ranted at in public.
     
    Doug Yoes likes this.
  15. I know I am hosted on DiscountASP
    I know my Website name
    I know the Folder name _Database (where the database is stored)
    I know the Database name test.mdb

    Thats all I know - nothing else

    I have 4 ingredients - are they enough to make a connection ?

    (I dont know what else to say)

    How do I use the above information to connect to my database - Please
     
  16. Apologies for doubting the quality of help - sincere apologies
    (This is based on the first response from Tasselhoff - thanks)

    I have it working - and it works like lightning

    WORKING SAMPLE CODE

    1) Put your MDB Database in Folder _Database
    2) Put the following code into Notepad, save as Test.ASP
    3) Copy Test.ASP to your website
    4) Open Internet Explorer and key into the addressbar
    www.yourwebsitename.com/test.asp



    Code:
    <%
     Dim cnnSimple  ' ADO connection
     Dim rstSimple  ' ADO recordset
     Set cnnSimple = Server.CreateObject("ADODB.Connection")
     
    ' DSNLess
     cnnSimple.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("_Database\ITMSuite.mdb"))
     
    Set rstSimple = cnnSimple.Execute("SELECT * FROM Members")
     %>
     
    <P> Connecting to Access with Ole connection </P>
     <table border="1">
     
    <%
     Do While Not rstSimple.EOF
     %>
     
     <tr>
       <td><%= rstSimple.Fields(0).Value %></td>
       <td><%= rstSimple.Fields(1).Value %></td>
       <td><%= rstSimple.Fields(2).Value %></td>
       <td><%= rstSimple.Fields(3).Value %></td>
       <td><%= rstSimple.Fields(4).Value %></td>
      </tr>
     
    <%
     rstSimple.MoveNext
     Loop
     %>
     
    </table>
     
    <%
     rstSimple.Close
     Set rstSimple = Nothing
     cnnSimple.Close
     Set cnnSimple = Nothing
     %>
     
  17. mjp

    mjp

    Nice, glad you got it worked out.
     
  18. Hi George,
    It's not too difficult to connect to an MS-Access database using ASP.Net.
    I have a simple example here:
    http://greenproductionss.com/Groceries_m.aspx

    But what is a little more difficult is connecting to it using PHP.
    Anyone have any good ideas?

    Green Lamar
    Email: [email protected]
    Website: www.GreenProductionss.com
     
  19. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page