?
Solved

Microsoft SQL Connection issue

Posted on 2005-04-07
7
Medium Priority
?
210 Views
Last Modified: 2010-04-07
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))
0
Comment
Question by:tonelm54
7 Comments
 
LVL 10

Expert Comment

by:lengreen
ID: 13726824
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
 
LVL 9

Expert Comment

by:Type25
ID: 13726903
"Data Source=192.168.0.27;User ID=myUser;Password=myPassword;Initial Catalog=myDatabase"
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 13726907
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:laotzi2000
ID: 13726931
Dim objConnection As New SqlConnection("Data Source=192.168.0.27;Network Library=DBMSSOCN;database=myDatabase;User ID=myUser; Password=myPassword;")
0
 
LVL 9

Expert Comment

by:Type25
ID: 13726966
Who's right i wonder...  

*drum roll*
0
 
LVL 8

Expert Comment

by:thrill_house
ID: 13727333
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
 
LVL 9

Accepted Solution

by:
Type25 earned 2000 total points
ID: 13727376
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question