Accessing the SQL Database available in other server with my same LAN

Hi,

Iam very new to VB.Net. Even I can say today only I started the project in VB.NET

My requirement:-

Currently we are having 3-servers. Myself is logged-in to server called - " SERVER-1 " & My User name with server - " Bond ", Password - " 007 "

And the SQL SERVER 2005 is available in another system and that server called "SERVER-2" and his user name is " Raj" , Password - "123"
but all are in same LAN


How to connect with that sql server available in another machine ?

The following details I collected from that sql server..........

Server Name : abcde2
user name : SERVER-1 Raj

Codings:
Dim con As New SqlConnection("server=server-2; database=emp_management; uid=Server-1Raj")

From MAHEY


Comments

  • seancampbellseancampbell Pennsylvania, USA
    Get the IP for your SQL Server (Open Start->Run, type in CMD and hit enter (A command prompt will appear). Type 'Ping abcde2' and hit enter, that should return the ip address when it is getting a response back from the server.

    [code]
    Dim ConStr as String = "Server=IPADDRESS;Database=emp_management; Uid=myUsername;Pwd=myPassword;"
    Dim Con as new SqlClient.SqlConnection(ConStr)
    [/code]
  • Hi,

    Thanks for your sincere & immediate reply....Also sorry for my delayed reply because of inconvinience....

    From my system I checked that server is conncting via remotely....
    ie...from run command- mstsc then that user name & Password for windows are enabling me to connect to that server...

    So How can I connect....? Is there anything for remote servers?

    Thanks From
    MAHEY

  • seancampbellseancampbell Pennsylvania, USA
    I am not sure what you are asking me exactly, I am sorry. If you are having trouble getting VB.Net to connect to your database, try something simple and go from there. I created a form with 1 button on it to test if I am creating a connection to a Database. I am using VB.Net 2005 (Framework 2.0).

    [code]
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Con As SqlClient.SqlConnection
    Con = New SqlClient.SqlConnection("server=1.2.3.4;uid=Admin;pwd=Pass;database=Web")
    Con.Open()

    If Con.State = ConnectionState.Open Then Button1.Text = "Worked"
    End Sub
    [/code]

    my Server = 1.2.3.4
    my Username = Admin
    my Password = Pass
    my Database Name = Web

    This code doesn't touch any tables yet, that will be in the SQL Statements I use with another object. If you can get this code to show that Con is open with your parameters, then the next step is to make sure your SQL statements are proper.

    Sorry that I cannot understand your question, if you restate it I may be able to help you farther.
  • Hi,

    Again Thanks To Those Kindness....

    My Requirement:

    We are having 3-servers. All the users are use to log-in by SERVER-1 and in LAN. My system User name with SERVER-1 is SERVER-1RAJ & Password 123

    Also the SQL SERVER 2005 is installed on SERVER-2

    And I checked manually........The following steps gave me the success connection

    1. From Run - Command I typed MSTSC
    2. Computer - SERVER-2
    3. When I click connect, Then it asked again
    USERNAME : administrator
    PASSWORD : 123
    LOG ON To : SERVER-1
    4. After login I can find the SQL SERVER 2005 on the Programs list
    and when I click SQL SERVER Management Studio Again it asked the
    following things....
    5. SERVER TYPE : DATABASE ENGINE
    SERVER NAME : SERVER-2
    AUTHENTICATION : WINDOWS AUTHENTICATION

    USER NAME : SERVER-1Administrator

    Then I click connect It's connecting successfully and can able read the
    datas.

    Now please explain me how to connect..........

    from MAHEY



  • seancampbellseancampbell Pennsylvania, USA
    Ok, I see that you can remote into the computer. But that doesn't really prove out much. The reason I was asking you to go into cmd and ping Server-1 was just to grab the IP incase you were having problems connection to the server because you had bad DNS credentials.

    Sounds like you don't know where to start, square one, with making a connection to a Database and grabbing data. In VB.Net we do not create a connection to any data during Design time (while your coding), but you will put in place code to establish a connection, verify the connection is open, then grab out the data.

    I can not help you write the exact code as I do not know the database design, or what you are trying to do, but I can assist you in obtaining a connection to the Database and how to grab out data and play with it.

    If you are having problems that are not related to VB.Net code, I also cannot assist you, I am not a SQL Server expert by any means, just some punk kid who knows some VB.net code.

    [code]

    'This is code to be used when you want to run
    'An Update, Delete, or Insert statement

    Dim SQLStr As String 'The SQL
    Dim SQLConn As New SqlConnection() 'The SQL Connection
    Dim SQLCmd As New SqlCommand() 'The SQL Command

    SQLConn.ConnectionString = ConnString 'Set the Connection String
    SQLConn.Open 'Open the connection

    SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
    SQLCmd.CommandText = SQLStr 'Sets the SQL String
    SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only

    SQLConn.Close() 'Close the connection

    [/code]

    [code]
    'This is code to use when you run a SELECT SQL STATEMENT

    Dim SQLConn As New SqlConnection() 'The SQL Connection
    Dim SQLCmd As New SqlCommand() 'The SQL Command
    Dim SQLdr As SqlDataReader 'The Local Data Store

    SQLConn.ConnectionString = ConnString 'Set the Connection String
    SQLConn.Open 'Open the connection

    SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
    SQLCmd.CommandText = SQLStr 'Sets the SQL String
    SQLdr = SQLCmd.ExecuteReader 'Gets Data

    While dr.Read() 'While Data is Present
    MsgBox(dr("Column Name")) 'Show data in a Message Box
    End While

    Loop While SQLdr.NextResult() 'Move to the Next Record
    SQLdr.Close 'Close the SQLDataReader

    SQLConn.Close() 'Close the connection

    [/code]

    I have work to do here, but I will try and get a second post that implements this code slightly with your credentials. I took this code from a post here: http://www.daniweb.com/code/snippet696.html which you might want to check out for more details (seemed pretty informative, granted I did not read the entire thing).
  • hay i have a library system and i use SQL 2000 and vb.net 2008 and i want to use the system through network ....and how can i do that ?

    this are some code i use in my project

    dim dt as new datatabel()
    dim dr as datarow
    dim constr as string ="provider.........."
    dim sqlStr as string ="SELECT * FROM mem"
    dim dataadapter as new sqlclinet.sqlclientdataadapter(sqlStr,constr)


    on form load ...
    dataadapter .fill(dt)
    dataadapter .dispos()
    end sub


  • This post has been deleted.
  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories