Sample code for Database Connection Using ASP or ASP.Net

Discussion in 'C#' started by gregishere, Jun 24, 2008.

  1. #1
    I have a windows webhosting and created a database, Anybody have a sample code for database connection from my asp page to my database server?

    Thanks in advance
     
    gregishere, Jun 24, 2008 IP
  2. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    ASP connection string

    
    <%
    Dim conn, rs
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.Open "Provider=SQLOLEDB;server=<Your database serve IP Address>;Database=<your database name>;uid=<your username>;pwd=<your password>"
    set rs = Server.CreateObject("ADODB.RecordSet")
    %>
    
    Code (markup):
    Save this code in conn.asp page and upload in your wwwroot or html_public folder

    for test you need to run your website page http://www.domainname.com/conn.asp
     
    shaileshk, Jun 24, 2008 IP
  3. gregishere

    gregishere Well-Known Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    Digital Goods:
    4
    #3
    Thanks a lot shaileshk, I will try it now
     
    gregishere, Jul 2, 2008 IP
  4. helpbeam

    helpbeam Guest

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Also you can go to connectionstrings.com. They have samples for almost every database type.
     
    helpbeam, Jul 2, 2008 IP
  5. gregishere

    gregishere Well-Known Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    Digital Goods:
    4
    #5
    I cannot connect in my server, i have this error.

    Microsoft OLE DB Provider for SQL Server error '80004005'

    [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

    /free-cellphoneringtones.com/connect.asp, line 5


    Is domainname Ip address different from Server Ip Address?

    Thanks
     
    gregishere, Jul 2, 2008 IP
  6. vodcoder

    vodcoder Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you want more information in less time, check out the video tutorials from codervods.com , they also have about database conectivity
     
    vodcoder, Jul 2, 2008 IP
  7. helpbeam

    helpbeam Guest

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Instead of Server try data source

    conn.Open "Provider=SQLOLEDB; Data Source = <IP of the server>; Initial Catalog = <YourDatabase>; User Id = youruid; Password=yourpassword"
     
    helpbeam, Jul 2, 2008 IP
  8. gregishere

    gregishere Well-Known Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    Digital Goods:
    4
    #8
    The problem is i used my server ip address, instead of my database ip, thats why its not working. But its working now, i tested and have good data output.

    Thanks evryone for your help appreciate it.
     
    gregishere, Jul 2, 2008 IP
  9. helpbeam

    helpbeam Guest

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    glad you got it working
     
    helpbeam, Jul 8, 2008 IP