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!

DataSet Intranet HTTP

Status
Not open for further replies.

tdtomlins

Programmer
Sep 20, 2002
6
US
How do I connect to a database on the server or "unsecure" internet site. I have tried the following and it works if I hard code a "C:\*.mdb" but when I place it does not work. SEE CODE BELOW

Any suggestions on how to access a Database using http????

Dim MyConnstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database.mdb;Persist Security Info=False"
'THIS DOES NOT WORK BELOW
'Dim MyConnstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Localhost/Database.mdb/; Persist Security Info=False"
'THIS DOES NOT WORK ABOVE

Dim strSQL As String = "Select * from Customers"
Dim cnn As OleDbConnection = New OleDbConnection(MyConnStr)
' Dim cmd As OleDbCommand = New OleDbCommand(strSQL, cnn)
Dim dr As DataRow
Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
da.SelectCommand = New OleDbCommand(strSQL, cnn)
da.Fill(ds)

DataGrid1.DataSource = ds
da.Dispose()
cnn.Close()
 
Not sure that the database can be accessed that way but you could use application path variables.

The other thing is that localhost doesn't point directly to C: like your first string but C:\Inetpub\ That'l do donkey, that'l do
[bravo] Mark
 
I really need to assess the DB using the URI format. I was trying to do it with a DataSet so I did not have to maintain connection and the ability to Update/Add to the database if needed. Wish I could map the drive but cannot. In VB6 ADO can use URI. and I believe the connection is working with the URI but the DataSet is not accepting it??

Any suggestions would be helpful.

Thanks
Tomlins
 
Why do you need the URL? format?

If your db server is going to be on another machine then the way to go would be to build a webservice. A webservice can be referenced through a URL and it returns datasets via XML. That'l do donkey, that'l do
[bravo] Mark
 
Wrote a solution. Documentation from microsoft "Creating a Distributed Application" is incorrect e-mailed MS on this and they have confirmed it. You do have to create a ASP web Service within this service created and OLEDbconnection and OLEDbDataAdapter and Dataset added two(2) methods
<WebMethod()> Public Function getData() As DataSet1
Dim objdata As New DataSet1()
OleDbDataAdapter1.Fill(objdata)
getData = objdata
End Function

<WebMethod()> Public Function SaveData(ByVal DataSave As DataSet1) As DataSet1
If Not (DataSave Is Nothing) Then
OleDbDataAdapter1.Update(DataSave)
Return DataSave
Else
Return Nothing
End If
End Function

COMPLIED THE WEB SERVICE FORM:

ADDED A VB.NET APPLICATION PROJECT;
Added Web REference to my WebService just created
Added Grid, Dataset and two buttons to form.
ADDED FOLLOWING CODE
'MyForm is the name of my form
'WebReference1 is the name of my WebService
'Service1 is the name of the created service in WebREference1

Dim ws As New WebReference1.Service1()

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

MyDataSet.Merge(ws.getData)
DataGrid1.DataSource = MyDataSet

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If MyDataSet.HasChanges Then
Dim ws As New MyTest.WebReference1.Service1()
Dim diffItems As New MyTest.WebReference1.DataSet1()
diffItems.Merge(MyDataSet.GetChanges())
diffItems = ws.SaveData(diffItems)

If diffItems Is Nothing Then
MessageBox.Show(&quot;No tables needing updated&quot;)
Else
MessageBox.Show(&quot;Updated Tables&quot;)
End If
MyDataSet.Merge(diffItems)
Else
MessageBox.Show(&quot;No tables needing updated&quot;)
End If

End Sub

This is really cool guy's I then place my EXE and and WebService on the Server and called my application MyTest.exe like a web page this loaded the application onto the clients machine and connected to the DB on the server.

Hope this helps
Tomlins
 
lol glad you liked it. My main job is web app development. I love this stuff.

Check out the Asp.net forum
forum855 That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top