Link to home
Start Free TrialLog in
Avatar of ukmedia
ukmedia

asked on

Couple of questions really

Hi There,

I have two questions really.

1. I have a modual that connects to a access database at present but I want to change this to connect to SQL SERVER 2000. Also what refrences would I need to add to the project?

Here is the code:

Public dbConn As Connection
Public recSet As ADODB.Recordset
Public Function DBConnect() As Boolean

On Error GoTo OpenErr

Dim MSDatabase

'Connects to Database
   Set dbConn = New Connection
   dbConn.CursorLocation = adUseClient
   dbConn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\Test.mdb;"
   
    DBConnect = True
Exit Function

OpenErr:

    MsgBox "Error Opening " & MSDatabase & vbNewLine & Err.Description, vbCritical, "Open Database Error"
    DBConnect = False


End Function

Also can anyone give me any ideas on what software I need to code a project for pocket PC also can this be coded in the vb langauge or another langauge?
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Its best to use a UDL file to specify the connection string.

1) Create a UDL File

Create a blank file, rename the file to MyConnection.UDL.
Double click on the file.
Click on the provider tab, select a provoder, then click next. Complete the following screen.
You get a chance to test the connection which means it works so if your code
won't work at least you know the connection string is good.

Move the file to your application folder.

2) Modify your code as follows:

dbConn.Open GetConnectionString(App.Path & "\MyConnection.UDL")

In this way your code will work with any type of database with an ADO client driver.

Hope this helps:~)

Public Function GetConnectionString(FileName As String) As String

' Use of this sub avoides the problem that of a connection file has been saved
' with extra lines at the end this will cause a crash.
Dim sFile As String

sFile = ReadFile(FileName)
sFile = StrConv(sFile, vbFromUnicode)

Dim lPos As Long
lPos = InStr(1, sFile, "Pprovider=", vbTextCompare)
sFile = Mid(sFile, lPos)

GetConnectionString = sFile

End Sub


Public Function ReadFile(FileName As String) As String

' Returns the contents of a file

'example
' SData=ADO.ReadFile("C:\MyStuff.txt")
'If Left(sData, 5) = "ERROR" Then
'    MsgBox sData
'    End
'End If

Dim wlfn As Long

wlfn = FreeFile
On Error Resume Next

If Len(Dir(FileName)) > 0 Then
    If Err.Number <> 0 Then
        ReadFile = "ERROR Invalid resource file path: " + FileName + " ~ " + Err.Description
        Exit Function
    End If
    Open FileName For Binary Access Read Shared As #wlfn
    ReadFile = Space$(LOF(wlfn))
    Get wlfn, 1, ReadFile
    Close wlfn
    If Err.Number <> 0 Then
        ReadFile = "ERROR in function ReadFile: " + FileName + " ~ " + Err.Description
        Exit Function
    End If
Else
    ReadFile = "ERROR Missing File " + FileName
End If

End Function


For pocket PC programming you need to download the eMbeded development kit available free from the Microsoft site.

All the stuff you need is here:

http://www.microsoft.com/windowsmobile/resources/downloads/developer/default.mspx

Its quite cute and includes an emulator that lets you develop and test your software as if its running on a pocket pc.
From the above link you can find this link which has all of the VB stuff you need.:

http://www.microsoft.com/windowsmobile/resources/downloads/developer/evb.mspx
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from ukmedia from 12/12/2003 comment
Award points to Dhaest is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer