?
Solved

Couple of questions really

Posted on 2003-12-11
6
Medium Priority
?
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 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