Connection string for PDA RRS feed

  • Question



    I am using VS 2005 and developing PDA device application to run on SQL CE. The PDA has Windows CE 5.0 OS.

    Now I am using the following code for connection to database: I got this code from some website on Internet but do not remember which one:

     Dim FullAppName As String = [Assembly].GetCallingAssembly().GetName.CodeBase
     Dim FullAppPath As String = Path.GetDirectoryName(FullAppName)

     Dim FullFileName As String = Path.Combine(FullAppPath, "Test123.sdf")
     Dim cn As New SqlCeConnection(String.Format("Data Source={0}", FullFileName))
     MessageBox.Show("Connection Success")

     Catch ex As Exception
     End Try
    Here the problem is that
    1. FullAppPath returns \Windows. But the database is in application folder i.e. \Program Files\DeviceSampleApp. Then why does it return \Windows.

    2. So I copied the test123.sdf file in \Windows folder. But cn.Open goes to catch block. This means there is some error but surprisingly ex.ToString displays blank messagebox. What could be the issue?

    3. I also changed the connection string as:
    Dim cn As New SqlCeConnection("Data Source = \Program Files\DeviceSampleApp\Test123.sdf") and the Test123.sdf correctly gets deployed to this folder \Program Files\DeviceSampleApp\ which also has the EXE. Still it gives error that it cannot find the database Test123.sdf in the path \Program Files\DeviceSampleApp\ but I checked and it is there. What could be the issue?



    Tuesday, September 11, 2007 4:18 PM


  •  GetCallingAssembly() would work if this code is in the DLL which is called from your EXE. If this code is in the EXE itself use GetExecutingAssemly() instead.

    Wednesday, September 12, 2007 5:36 AM

All replies