Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to SQLServer database

Status
Not open for further replies.

newbie1983

Programmer
Sep 9, 2003
52
0
0
GB
HI,

I am quite new to databases, i am currently writing a system with a visual basic 6 front end which will use a sqlserver2000 back-end. Does anyone know how to connect to a sqlserver database in visual basic 6?(as in the source code) Any replies would be greatly appreciated

Regards,

newbie1983
 
If you're using ADO (Reference MS ADO 2.6) you can use the following:

Code:
Dim myConnection as new Connection

myConnection.Open "Provider=sqloledb;" & _ 
           "Data Source=myServerName;" & _
           "Initial Catalog=myDatabaseName;" & _
           "User Id=myUsername;" & _
           "Password=myPassword"

Hope it helps!
B
 
Hi Bernini!

thanks for your reply, i was just wondering where in the code you specified do i place the path of where the database is? i.e source = "C:\program file....\database.MDF" ?

any help is much appreciated

Regards

newbie1983
 
To use MSSQL you refer to the SQL server and the Initial Catalog (which is the database name on the server) as shown in the example above. As far as I know you can't access the actual datafile directly, that's what the server is for.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
hi johnwm,

i basically just need to make the connection from the vb front end to the database itself on sqlserver2000 not the actual datafile, i am quite new to this so i dont know what the database extention is - i assumed it was .MDF?

regards

newbie1983

 
You don't need the file path or extension - SQL server looks after that. Did you try the example given above?

If the connection string that Bernini gave you doesn't work for you (maybe you want to use trusted connection rather than user/password) then there is a comprehensive list of ADO connection strings here:


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thanks Bernini + johnvm for your help. Is there a universal way of displaying and adding records from SQLServer database using ADO?

Regards

newbie1983
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top