VB2008 and Connection to SQL
0
Q:
VB2008 and Connection to SQL
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: Apr 9 2009  12:32 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
390 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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
Last Answered: Apr 9 2009  3:49 PM GMT by RoadDust   390 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Alessandro.panzetta   9615 pts.  |   Apr 10 2009  6:59AM GMT

I didn’t try that and directly installed another version that allows me any conenction type.
Thanks anyway.

 

CarlSSDBA   10 pts.  |   Aug 5 2009  6:49PM GMT

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

 
0