Microsoft SQL Connection issue

I am trying to connect to a Microsoft SQL 2000 server with the following code, but cannot get it to work, any idea?

Tony

        Dim objConnection As New SqlConnection("Data Source=192.168.0.27;database=myDatabase;User ID=myUser; Password=myPassword;")
        Dim strSQL As String = "Select * from users"
        Dim objAdapter As New SqlDataAdapter(strSQL, objConnection)
        Dim objReader As SqlDataReader = Nothing
        objConnection.Open()
        objReader.Read()
        Response.Write(objReader.GetValue(1))
tonelm54Asked:
Who is Participating?
 
Type25Connect With a Mentor Commented:
That's true...

try this:

Dim Cnn As SqlConnection =  New SqlConnection("Data Source=192.168.0.27;User ID=myUser;Password=myPassword;Initial Catalog=myDatabase"")
Cnn.Open()
Dim reader As SqlDataReader
Dim Cmd As SqlCommand =  New SqlCommand("SELECT * FROM Users",Cnn)
reader = Cmd.ExecuteReader()
 
While reader.read()
   Response.Write(reader(0).ToString())
End While
 
reader.Close()
Cnn.Close()
0
 
lengreenCommented:
Hi tonelm54,
try

"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"

if you need anyother connection strings take a look at http://www.connectionstrings.com/

Cheers!
0
 
Type25Commented:
"Data Source=192.168.0.27;User ID=myUser;Password=myPassword;Initial Catalog=myDatabase"
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
nauman_ahmedCommented:
Sometimes the connectionstring in this format has issues...you can try the following if you dont have anyluck :)


workstation id=MYSQLServer;packet size=4096;initial catalog=MY_DB;user id=sa;password=PASSWORD;data source=MYSQLSERVER;persist security info=False;

HTH, Nauman.
0
 
laotzi2000Commented:
Dim objConnection As New SqlConnection("Data Source=192.168.0.27;Network Library=DBMSSOCN;database=myDatabase;User ID=myUser; Password=myPassword;")
0
 
Type25Commented:
Who's right i wonder...  

*drum roll*
0
 
thrill_houseCommented:
This part sure seems like a problem:
Dim objReader As SqlDataReader = Nothing
        objConnection.Open()
        objReader.Read()
        Response.Write(objReader.GetValue(1))

You never set the DataReader to anything, but then you reference it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.