Results 1 to 12 of 12

Thread: SQL Problem (?)

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    SQL Problem (?)

    Hi!
    Im working on a little Programm
    Ive tried to connect to the SQL Database from My Webspace.
    But it doesnt Work...
    Here is the Code:
    VB Code:
    1. Dim Server = My.Forms.LoginForm1.TextBox1.Text
    2.  
    3.         Dim strCon As String = "Data Source=IP;" & _
    4.         "Initial Catalog= hidden;" & _
    5.         "User ID=hidden;" & _
    6.         "Password=hidden"
    7.  
    8.         Dim con As SqlConnection = New SqlConnection(strCon)
    9.         Dim strSQL As String = "SELECT * FROM Server"
    10.         Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, con)
    11.        
    12.         Dim ds As New DataSet
    13.         Dim ds2 As New DataSet
    14.         da.Fill(ds)
    15.  
    16.         Dim tbl As DataTable = ds.Tables(0)
    17.         Dim row As DataRow = tbl.NewRow()
    18.  
    19.  
    20.         Me.Label4.Text = row("servername")
    21.         Me.LinkLabel1.Text = row("serverhomepage")
    Can any help me?
    You See that "Server" is Variable.... its mean the text that was tyoed in the Textfield in antother Form.

    Greetz Malle

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: SQL Problem (?)

    its not variable because you put it inside your quotes.

    VB Code:
    1. Dim strSQL As String = "SELECT * FROM " &  Server

    also I can't remember if the connection opens automatically when using a dataset, but if it doesn't you need to make a call to con.open.


    server is not the best name for that variable too, because select statements go against tables inside a database on a server, you dont do a select statement on a specific server...
    Last edited by kleinma; Dec 21st, 2006 at 11:06 AM.

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: SQL Problem (?)

    First of all, your connection string doesn't look legitimate....
    VB Code:
    1. Dim strCon As String = "Data Source=IP;" & _ 'You need to put in the actual IP address of the server hosting your database here, e.i "Data Source=192.168.0.230
    2.         "Initial Catalog= hidden;" & _ 'Is the actual name of the catolog "hidden" ?
    3.         "User ID=hidden;" & _ ' Is the actual User ID is "hidden" ?
    4.         "Password=hidden" 'Is the actual password for the above user ID "hidden"?
    Secondly, on your select statement, you have
    VB Code:
    1. Dim strSQL As String = "SELECT * FROM Server" 'Is there a table named "Server" in your database?
    Once you get these thing traighten out, we can go further on any other issues.

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: SQL Problem (?)

    Quote Originally Posted by stanav
    First of all, your connection string doesn't look legitimate....
    VB Code:
    1. Dim strCon As String = "Data Source=IP;" & _ 'You need to put in the actual IP address of the server hosting your database here, e.i "Data Source=192.168.0.230
    2.         "Initial Catalog= hidden;" & _ 'Is the actual name of the catolog "hidden" ?
    3.         "User ID=hidden;" & _ ' Is the actual User ID is "hidden" ?
    4.         "Password=hidden" 'Is the actual password for the above user ID "hidden"?
    Secondly, on your select statement, you have
    VB Code:
    1. Dim strSQL As String = "SELECT * FROM Server" 'Is there a table named "Server" in your database?
    Once you get these thing traighten out, we can go further on any other issues.
    i have replace my real id,pw etc with hidden because i dont want to publish this information^^

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: SQL Problem (?)

    ehm....
    Question
    Initial Catalog is the Database of my Sql Acount right?

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: SQL Problem (?)

    you don't actually need it.. here is an example connection string

    VB Code:
    1. "Persist Security Info=False;Integrated Security=false;database=DATABASE_NAME_HERE;server=SERVER_OR_IP_HERE;User ID=USER_ID_HERE;Password=PASSWORD_HERE"

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: SQL Problem (?)

    i see in the config.inc.php of my forum that in the Line host the value is: localhost

    is that a problem?

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: SQL Problem (?)

    are you writing VB code here, or PHP code???

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: SQL Problem (?)

    vb but in for my real id etc i have open a php file where i can read it ....

    $host="localhost";


    is that a problem to connetc from my Programm to the SQL server?

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: SQL Problem (?)

    Not really sure what you mean to be honest.. however I can tell you that localhost points to the local machine (aka the SAME machine) that the code is running on. It points to 127.0.0.1 or a machines internal loopback address.

    So if the code and the server are not on the same machine, then you need to specify what machine it needs to connect to.

  11. #11

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: SQL Problem (?)

    VB Code:
    1. Dim Server = My.Forms.LoginForm1.TextBox2.Text
    2.  
    3.         Dim strCon As String = "Persist Security Info=False;Integrated Security=false;database= mydb;server=213.203.202.153;User ID=myusername;Password=mypassword"
    4.         Dim con As SqlConnection = New SqlConnection(strCon)
    5.         con.Open()
    6.  
    7.         Dim strSQL As String = "SELECT * FROM " & Server
    8.         Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, con)
    9.        
    10.         Dim ds As New DataSet
    11.         Dim ds2 As New DataSet
    12.         da.Fill(ds)
    13.  
    14.         Dim tbl As DataTable = ds.Tables(0)
    15.         Dim row As DataRow = tbl.NewRow()
    16.  
    17.  
    18.         Me.Label4.Text = row("servername")
    19.         Me.LinkLabel1.Text = row("serverhomepage")
    20.  
    21.  
    22.         '        Dim Server = My.Forms.LoginForm1.TextBox1.Text
    23.         '       Dim cmd As New SqlCommand
    24.         '      cmd.CommandText = "INSERT INTO SERVER_USER"
    25.         '     cmd.Connection = con
    26.  
    27.  
    28.  
    29.  
    30.  
    31.  
    32.  
    33.  
    34.         con.Close()

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: SQL Problem (?)

    ok...now i know why it doesnt work:
    My Server Admin doesnt allow that a program connect to the SQL Server...
    But i can make it via Files...
    How i connect to a FTP Server?

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