Solved

Couple of questions really

Posted on 2003-12-11
6
154 Views
Last Modified: 2010-05-03
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?
0
Comment
Question by:ukmedia
  • 3
6 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 50 total points
ID: 9926522
1) You don't need any other reference. Only your connectionstring (dbconn.open) must change

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

For more connectionstrings: see http://www.able-consulting.com/MDAC/ADO/Connection/OLEDB_Providers.htm#OLEDBProviderForSQLServer

2) For more information about programming for an pocket PC see http://www.devbuzz.com/
0
 
LVL 17

Expert Comment

by:inthedark
ID: 9926527
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


0
 
LVL 17

Expert Comment

by:inthedark
ID: 9926544
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.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 9926562
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
0
 
LVL 27

Expert Comment

by:planocz
ID: 10289445
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now