Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2006, 11:09 AM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to haron_Master Send a message via AIM to haron_Master Send a message via MSN to haron_Master Send a message via Yahoo to haron_Master
Default Pls i need Ur help How 2 cnect VB6 DTBASE SQL SVR

Please any body can help me how to connect vb6 to sql server database i'm very appreciated if someone can help and millions of thanks

none
__________________
none
 
Old March 11th, 2006, 03:18 AM
Authorized User
 
Join Date: Mar 2006
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Raghunathan
Default

hi

U Can use Microsoft ActiveX Data Object(ADO).

Open a Standard EXE Project in VB
Goto Project Menu --> select References
Select the Reference "MICROSOFT ACTIVEX DATA OBJECT x.x" where x.x can be [ 2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8 (all are different versions)]

Select any one version and click ok

Then Try the following code

Sub ConnectToSQL()
Dim ObjSQLCon As ADODB.Connection
Set ObjSQLCon = New ADODB.Connection

ObjSQLCon.Open "Provider=SQLOLEDB;User Id=username;Password=passwd;Data Source=sqlservermachinename;Initial Catalog=dbname"

If ObjSQLCon.State = adStateOpen Then
    Msgbox "SQLConnection Opened",vbInformation
Else
    MsgBox "SQLConnection Failed"
End If

End Sub

Here in the Open() method of ADODB.Connection Object, these values should be passed correctly else it will not connect.

Provider=SQLOLEDB; 'OLE DB Provider for SQL Server (do not change this value)

Data Source=sqlservermachinename; 'Should be the name of the server in which SQL Server is running

Initial Catalog=dbname; 'Name of the SQLServer Database that u wish to u connect

User Id=username; 'Should be a valid SQL Server username

Password=passwd; 'Should be a valid SQL Server password


Regards,
Raghu
 
Old March 11th, 2006, 03:52 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's a tutorial that may be helpful.

VB Database Programming: http://www.vbexplorer.com/VBExplorer...er_ADO_DAO.asp

- A.Kahtava
 
Old March 12th, 2006, 12:23 PM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to haron_Master Send a message via AIM to haron_Master Send a message via MSN to haron_Master Send a message via Yahoo to haron_Master
Default

Thank you very much for your reply please if you can,can you show me in DAO COMMAND cause i' using DAO i'M familiar with DAO command

none
 
Old March 12th, 2006, 07:14 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DAO example - JET Connection

Dim ws as Workspace
Dim db as Database

Set ws=DBEngine.Workspaces(0)
set db=ws.OpenDatabase({databasepath and name})

DAO example - ODBC Connection

Dim ws as Workspace
dim db as database
dim strConnection as string

set ws=DBEngine.Workspaces(0)
let strConnection= "ODBC;DSN=" & DatabaseName & ";UID=" & UserName & ";PWD=" & UserPassword
set db=ws.OpenDatabase("", False, False, strConnection)

-------
The link I posted in my last post has examples of both ADO and DAO.
Above code taken from the link in my last post.

- A.Kahtava
 
Old March 13th, 2006, 10:27 AM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to haron_Master Send a message via AIM to haron_Master Send a message via MSN to haron_Master Send a message via Yahoo to haron_Master
Default

Thank you very much i'll try

none
 
Old March 13th, 2006, 01:15 PM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to haron_Master Send a message via AIM to haron_Master Send a message via MSN to haron_Master Send a message via Yahoo to haron_Master
Default

Please can you specify for me cause i'm new Programmers for VB
ODBC = ?
WHAT IS THE VALUE OF ODBC ?
AND MY DATABASE set db=ws.OpenDatabase(" ? ", False, False, strConnection)
set ws=DBEngine.Workspaces(0)
let strConnection= "ODBC;DSN=" & DatabaseName & ";UID=" & UserName & ";PWD=" & UserPassword
set db=ws.OpenDatabase("", False, False, strConnection)

none
 
Old March 14th, 2006, 02:30 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What is ODBC?
"Open Database Connectivity (ODBC) provides a standard software API method for using database management systems (DBMS)."
Read more at: http://en.wikipedia.org/wiki/ODBC

set db=ws.OpenDatabase("c:\Directory_Name\DatabaseName.mdb", False, False, strConnection)

You can either specify the database file in the OpenDatabase() method or the stConnection.

- A.Kahtava
 
Old March 15th, 2006, 01:55 PM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to haron_Master Send a message via AIM to haron_Master Send a message via MSN to haron_Master Send a message via Yahoo to haron_Master
Default

THANK YOU VERY MUCH

none
 
Old March 19th, 2006, 12:26 PM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to haron_Master Send a message via AIM to haron_Master Send a message via MSN to haron_Master Send a message via Yahoo to haron_Master
Default

hello my friend thank you for your reply i just want to ask you please can you show me your code if you can like if i delete my files in database using command delete i can retrieved my files or restore to my database my files thank you?.

none

none





Similar Threads
Thread Thread Starter Forum Replies Last Post
sql count function - urgent and pls help miki SQL Language 1 June 14th, 2006 09:47 AM
pls help SQL Queries sush_blr SQL Server 2000 2 February 1st, 2005 01:56 AM
pls help me to write sql queries sush_blr SQL Language 1 January 28th, 2005 10:20 AM
http image retrieval from rem svr to local web svr Stuart Stalker Classic ASP Professional 0 December 30th, 2004 12:07 PM
sql count function - pls help and urgent miki MySQL 1 May 12th, 2004 05:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.