Hi Timol
Welcome to careersng!
I tot u were going to make another post to the programming room so that i could post a reply but i didnt see it there.
Anyway back to your question. How to connect to SQL server from VB
Its quite easy to connect to Acces Database from VB because AccessDB is in form of a file and does not explicitly require the database engine to be runing on the target machine. So you can even deploy an Access DB file to a machine that does not even have the Microsoft Office installed on it. Once the machine is running windows from 2000 upward i guess.
On the other hand, SQL server requires the Engine to be running on the machine where you want to run the Application. Therefore you cannot connect to SQL server by writing the file path just as you do fo MS Access. The Easiest and most used way to connect to SQL server is to create a DSN - Data Source Name.
The DSN has all the required configuration you need for the connection. Take the following steps to create a DSN
1.) From your desktop (windows on target please) click start menu - control panel - Administrative tools (from windows 2000 i am sure of)
2.) Double-click to open Admin tools and open Data Sources (ODBC)
3.)You can create 3 types of DSN - User DSN for ur windows login alone (i.e only you can use it), System DSN for the Machine, File DSN as a file:- it can be attached to ur application and u can edit and use it on another machine
For this purpose we create a SYSTEM DSN
4.) Click the System DSN tab and click ADD
5.) From the list of Drivers Select SQL Server
6.) Click Finish
7.) In the Name box put the name you want to give to the DSN
8.) You can give description to the DSN
9.) Select the name of you SQL Server (default is local)
10.) Click Next
11.) If you are on a your local machine, click next till you get to the Finish button.
12.)You can then test the connection and if successful then you are done
You are through with the DSN creation
In your VB code do this
dim olcon as ADO.Connection
set olcon = new Ado.Connection
with olcon
.connectionstring = "DSN=myDsname; user ID= mySQLServerUserid; pwd=mySQLServerPassword"
.connectiontimeout = 'set any time of your choice
end with
you can continue from here i guess
Have a cool coding and if there is any other issue just mail me or better still chat with me (
seyigboye2000@yahoo.com)
Enjoy!