|
-
Dec 21st, 2006, 10:50 AM
#1
Thread Starter
Member
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:
Dim Server = My.Forms.LoginForm1.TextBox1.Text
Dim strCon As String = "Data Source=IP;" & _
"Initial Catalog= hidden;" & _
"User ID=hidden;" & _
"Password=hidden"
Dim con As SqlConnection = New SqlConnection(strCon)
Dim strSQL As String = "SELECT * FROM Server"
Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, con)
Dim ds As New DataSet
Dim ds2 As New DataSet
da.Fill(ds)
Dim tbl As DataTable = ds.Tables(0)
Dim row As DataRow = tbl.NewRow()
Me.Label4.Text = row("servername")
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
-
Dec 21st, 2006, 11:02 AM
#2
Re: SQL Problem (?)
its not variable because you put it inside your quotes.
VB Code:
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.
-
Dec 21st, 2006, 11:03 AM
#3
Re: SQL Problem (?)
First of all, your connection string doesn't look legitimate....
VB Code:
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
"Initial Catalog= hidden;" & _ 'Is the actual name of the catolog "hidden" ?
"User ID=hidden;" & _ ' Is the actual User ID is "hidden" ?
"Password=hidden" 'Is the actual password for the above user ID "hidden"?
Secondly, on your select statement, you have
VB Code:
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.
-
Dec 21st, 2006, 11:10 AM
#4
Thread Starter
Member
Re: SQL Problem (?)
 Originally Posted by stanav
First of all, your connection string doesn't look legitimate....
VB Code:
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
"Initial Catalog= hidden;" & _ 'Is the actual name of the catolog "hidden" ?
"User ID=hidden;" & _ ' Is the actual User ID is "hidden" ?
"Password=hidden" 'Is the actual password for the above user ID "hidden"?
Secondly, on your select statement, you have
VB Code:
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^^
-
Dec 21st, 2006, 11:23 AM
#5
Thread Starter
Member
Re: SQL Problem (?)
ehm....
Question
Initial Catalog is the Database of my Sql Acount right?
-
Dec 21st, 2006, 11:27 AM
#6
Re: SQL Problem (?)
you don't actually need it.. here is an example connection string
VB Code:
"Persist Security Info=False;Integrated Security=false;database=DATABASE_NAME_HERE;server=SERVER_OR_IP_HERE;User ID=USER_ID_HERE;Password=PASSWORD_HERE"
-
Dec 21st, 2006, 11:34 AM
#7
Thread Starter
Member
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?
-
Dec 21st, 2006, 11:36 AM
#8
Re: SQL Problem (?)
are you writing VB code here, or PHP code???
-
Dec 21st, 2006, 11:39 AM
#9
Thread Starter
Member
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?
-
Dec 21st, 2006, 11:45 AM
#10
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.
-
Dec 21st, 2006, 11:48 AM
#11
Thread Starter
Member
Re: SQL Problem (?)
VB Code:
Dim Server = My.Forms.LoginForm1.TextBox2.Text
Dim strCon As String = "Persist Security Info=False;Integrated Security=false;database= mydb;server=213.203.202.153;User ID=myusername;Password=mypassword"
Dim con As SqlConnection = New SqlConnection(strCon)
con.Open()
Dim strSQL As String = "SELECT * FROM " & Server
Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, con)
Dim ds As New DataSet
Dim ds2 As New DataSet
da.Fill(ds)
Dim tbl As DataTable = ds.Tables(0)
Dim row As DataRow = tbl.NewRow()
Me.Label4.Text = row("servername")
Me.LinkLabel1.Text = row("serverhomepage")
' Dim Server = My.Forms.LoginForm1.TextBox1.Text
' Dim cmd As New SqlCommand
' cmd.CommandText = "INSERT INTO SERVER_USER"
' cmd.Connection = con
con.Close()
-
Dec 21st, 2006, 12:00 PM
#12
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|