Results 1 to 3 of 3

Thread: Connecting to SQL Server hostname from VB .net

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    13

    Connecting to SQL Server hostname from VB .net

    Hello Experts. I need your help please

    I have a VB .net program that I have been using for a while. The program is written using VB .net 2005. It access SQL server 2005 which is local on the same machine the program resides. I have been asked to connect to a 2012 server or 2008 using
    " The server hostname SSQL02BLA1, I spoke with the DBA and he said that he connects to it via TCP/IP and doesn't use the name of the server instance."
    In the past I used the following code to connect to the local server and everything works fine:

    Imports System.Data.SqlClient

    Public Class

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

    Dim DBadp As New System.Data.SqlClient.SqlDataAdapter
    Dim command As New System.Data.SqlClient.SqlCommand

    DBconn = New System.Data.SqlClient.SqlConnection

    DBconn.ConnectionString = "Data Source=.;AttachDbFilename = " & str_data & ";Integrated Security=True;"

    Dim dtclient As New DataTable
    dtclient.Clear()
    If DBconn.State = ConnectionState.Closed Then
    DBconn.Open()
    End If
    DBadp = New System.Data.SqlClient.SqlDataAdapter("select * from clientdb", DBconn)

    DBadp.Fill(dtclient)
    DBconn.Close()
    End Sub
    End Class

    I need your help on what to do to change the connection as requested to SQL 2012 and connect to the server hostname SSQL02BLA1.
    Also, do I need to make any other changes on the code when accessing data?
    In the past I did a direct access now the request is for a remote access.
    PLEASE HELP thanks in advance!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Connecting to SQL Server hostname from VB .net

    Go to www.connectionstrings.com for all your connection string needs.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    13

    Re: Connecting to SQL Server hostname from VB .net

    Quote Originally Posted by jmcilhinney View Post
    Go to www.connectionstrings.com for all your connection string needs.
    Thank you so much

Tags for this Thread

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