Results 1 to 4 of 4

Thread: Connecting a SQL Server database to an ASP.NET web page

  1. #1

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    828

    Connecting a SQL Server database to an ASP.NET web page

    I have this for Ascess in my page.aspx.vb web page:

    Code:
            Dim dbCn As New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; " & "Data Source=" & Server.MapPath("\databases\CT-F1-servdatabase.mdb;"))
    How do I change that when using a SQL Server database so that the path works on my localhost and on the webserver?

    Thanks
    Peekay
    Frenetic member.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Connecting a SQL Server database to an ASP.NET web page

    SQL Server uses SqlConnection: https://learn.microsoft.com/en-us/do....sqlconnection

    Your connection string will change slightly:
    Code:
    ' using windows authentication
    Server=localhost;Database=CT-F1-servdatabase;Trusted_Connection=True;
    ' or using a username/password
    Server=localhost;Database=CT-F1-servdatabase;User Id=changeme;Password=changeme;
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    828

    Re: Connecting a SQL Server database to an ASP.NET web page

    Thank you dday9,
    So, can I use any SQL Server database with a static IP address or must I host the darabase on my webhosting service as a localhost?
    Peekay
    Frenetic member.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Connecting a SQL Server database to an ASP.NET web page

    You can connect to a remote database, although most will require that you whitelist the IP that you are querying from so that your database server isn't wide open to the entire web.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width