VB2008 and Connection to SQL

9,725 pts.
Tags:
SQL Server connectivity
VB 2008
Visual Basic
Visual Basic .NET Web services
Is there any way to connect to a SQL server using Vb2008? I'm trying to add a datasource but this allows me to conenct locally only.
ASKED: April 9, 2009  12:32 PM
UPDATED: December 5, 2011  10:12 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

Have you tried adding a DSN on your computer and connect it to your SQL database? Then create the datasource in Visual Basic and point to the DSN. If it ask you for type when creating the datasource you would select ODBC Databases. If you don’t want to have to create a DSN then you can connect using the following code:

Private Sub Command1_Click()
Dim Cn As New rdoConnection ‘creatable rdoConnection
Dim Qr As New rdoQuery ‘creatable rdoQuery
Dim Rs As rdoResultset ‘pointer to rdoResultset
Dim cnstr As String ‘hold connection info

cnstr = “driver={SQL Server};server=myserver;” & _
“database=pubs;uid=<username>;pwd=<strong password>”
Cn.Connect = cnstr

Cn.CursorDriver = rdUseClientBatch
Cn.EstablishConnection Prompt:=rdDriverNoPrompt
Set Qr.ActiveConnection = Cn
Qr.SQL = “Select * From Authors”
Set Rs = Qr.OpenResultset(Type:=rdOpenKeyset, _
LockType:=rdConcurBatch)
Debug.Print Rs(0), Rs(1), Rs(2)
End Sub

Please let me know if this helped.
Dustin

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • alessandro.panzetta
    I didn't try that and directly installed another version that allows me any conenction type. Thanks anyway.
    9,725 pointsBadges:
    report
  • CarlSSDBA
    Dustin, I think your suggestion is the path to the answer to my problem. (Have you tried adding a DSN on your computer and connect it to your SQL database? ) I am trying to use VB2008 Express to access a SQL Server 2008 database in Windows Vista. I used your suggestion to create a DSN (Start > Control Panel > Administrative Tools > Data Sources (ODBC) > System DSN > Add > SQL Server). What I dont' know is how to connect it to my SS database. Would you please help me on that? Thanks. CarlSSDBA
    10 pointsBadges:
    report
  • Kefyilal
    to gain detail knowlede by studying
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following