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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get VB to access a database on my website? 1

Status
Not open for further replies.

DarkMercenary44

Technical User
May 19, 2000
55
US
I want to have my VB program access a database on my website, and be able to retrieve the information stored within and then later on write to the same database, all without actually downloading the database, I could also do it with a text file it that is easier. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Use ADO to connect to the database, and issue SQL queries against it. You can use SQL Server, MS Access, or even mySQL for this. The database stays on whatever database server you're using -- only the records selected get sent over the network.

For info on how to use ADO, doa keyword search in this forum and/or the "Visual Basic(Microsoft) Databases" forum for the word ".ActiveConnection", or maybe ".CommandText".

Chip H.
 
i think the scenario is like this:

database -> web -> vb app
database <- web <- vb app

in this case, you cannot make a direct ado connection to the database because the data has to pass through the web platform (id assume iis). to pass data and retrieve data to and from the database you need to code a script at the web platform.

at the web platform (id assume you know asp) create the following:

a) a listening code -

listen.asp that reads a querystring and passes it to the databases (e.g. listen.asp?name=rcaluste&id=10)

the code for the listen.asp could be:

<% set conn = server.createobject(&quot;adodb.connection)
rs.open mytablename, conn
rs.addnew
rs!name = request.querystring(&quot;name&quot;)
rs!id = request.querystring(&quot;id&quot;)
rs.close
set rs = nothing
conn.close
set conn = nothing
%>

b) a relay code -

relay.asp queries the database and persists the recordset as an xml file to the response stream. the vb app can then open the stream and convert it back to a recordset.

for your vb app you can use the internet transfer control:

e.g. pass data to the database

inet1.openurl(&quot; & varname & &quot;&id=&quot; & varid)

to get data from a database

varXmltoRS = inet1.openurl(&quot;
convertXMLtoRS(varXmltoRS)*

refer to the Microsoft Knowledge Base article on Convertin an XML stream back to Recordset for further information.

hope this helps.

arcanist
 
Thanks both of you, I've tried the XML thing, I found an author on PSC who did it, but it won't work on my webhoster, those cheapskates don't have XML installed, and I pay for the service to, they only have File System Object, PHP, ASP, IIS, SSI, etc, and ADODB connection abilities, that is why I was searching for some other way to do this besides the XML thing, but I guess there isn't.

Thanks anyways DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
As long as the site supports ADO you don't need to have the XML installed. What's they're probably saying is that they don't have the native support of their database for xml (like SQL server's XML support).. BUT..

ADO can already persist a recordset to xml. You also said that iis is already installed so this asp code will work:

relay.asp
<%
set conn = server.createobject (&quot;adodb.connection&quot;)
conn.Open [your connection string
set rs = server.createobject (&quot;adodb.recordset&quot;)
rs.open tablename, conn, adOpenDynamic, adLockPessimistic
Response.ContentType = &quot;text/xml&quot;
Response.Write &quot;<?xml version='1.0' encoding='ISO-8859-1'?>&quot; & vbCRLF
rs.save Response, 1
rs.close
conn.close
set rs = nothing
set conn = nothing
%>

try it!

arcanist
 
Hi,

If your webserver does not support ASP (which is the esiest solution), you can allways use CGI (Common Gateway Interface). You can write some code in vb that enables the vb program to communicate with a webform using CGI.

goto where you'll find a module that does all the work. As I remember it the zip file includes a lot of exampels.
Remember that the exe that you make must be placed in your webserver script directory (usually called /cgi-bin).


Sunaj
 
Alright I'll try it arcanist, and see if it works. Sunaj, I want the VB executable to reside on a users machine not the server, my program is a RPG online server and client, people who run the servers should be able to insert thier IP addy into my database on my site, or thiers if they wish. I'm doing this now with FTP uploading of a text file, and then clients who want to play should be able to connect to my site and get the latest server list, using thier copy of the program, also doing this with the FTP downloading of text file, I want to use the database because its quicker and with FTP, only a couple of people can download the same file at once[I think]


Arcanist, could you point me someplace that shows how to create the connection string, I've looked through all my vb books and can't find anything that will help, I'm using a MS ACCESS database. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
this might help:

&quot;driver={Microsoft Access Driver (*.mdb)};dbq=&quot; & server.mappath(&quot;yourdatabase.mdb&quot;)

if you use it to connect to your database using asp, its like this:

<%
set conn = server.createobject (&quot;adodb.connection&quot;)
conn.open &quot;driver={Microsoft Access Driver (*.mdb)};dbq=&quot; & server.mappath(&quot;yourdatabase.mdb&quot;)
%>

arcanist
 
Thanks alot arcanist, wish I could give you more stars but tek-tips won't let me, :) thanks for all the help, I'll try that today
DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
ADODB.Connection.1 error '800a0bb9'

The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.

/listen.asp, line 9

I get this error, heres what I have in my listen.asp page....

<%
dim rs
dim doc
dim cn
dim rqs

' Create Objects
set cn = server.CreateObject(&quot;ADODB.Connection&quot;)
cn.open &quot;driver={Microsoft Access Driver (*.mdb)};dbq=&quot; & server.mappath(&quot;mydb.mdb&quot;)
cn.Close
set cn = nothing
%>

I didn't write the whole thing cause I just wanted to test it and see if it would open.
DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
i usually get that error with the wrong pair of cursorlocation, cursor type and lock type. (it will report that the arguments are in conflict with one another.) However, I have tested the connection string under IIS and it works.

it is usually helpful if you have the adovbs.inc when using ado constants in your asp code. put it in your code like so:

<!--#INCLUDE FILE=&quot;adovbs.inc&quot; -->

you can easily this file for download anywhere in the internet.

<%
dim rs
dim doc
dim cn
dim rqs

' Create Objects
set cn = server.CreateObject(&quot;ADODB.Connection&quot;)
cn.open &quot;driver={Microsoft Access Driver (*.mdb)};dbq=&quot; & server.mappath(&quot;mydb.mdb&quot;)
set rs = server.createobject(&quot;ADODB.Recordset&quot;)
rs.open mytable, cn, adOpenDynamic, adLockPessimistic
rs.close
set rs = nothing
cn.Close
set cn = nothing
%>

i will also take a look at the alternative for the connection string to connect to an access database (the thing that comes to my mind is the use of a DSN but i put that as the last option.)

arcanist
 
I'm really grateful for all the help your giving me arcanist, hopefully I'll get it to work. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top