[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Visual Studio SqlCeConnection for Smart Device: SDF opening problem

Posted on 2011-04-20
2
Medium Priority
?
1,482 Views
Last Modified: 2013-12-27
I am a student trying to integrate a database into a smart device project using Visual Studio 2008. I want to run some SQL queries when a form loads to populate a combo box, and I think I have the code to open a database as a SqlCeConnection, but must be missing something. When i open the form, it tells me that "The database file cannot be found".

I'm pretty sure I have the SDF file embedded in the project (its new to me, so i might be looking at it wrong). Can't understand why it's unable to find the database. My ultimate goal is to populate the combo box as a first step; What am i doing wrong here?
Private Sub frmItemSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Dim strSql As String = "SELECT [BAR_CODE] FROM INVENTORY WHERE [USER_ID] = 12345"
        Dim strPath As String = "Data Source=AppDatabase1.sdf;Persist Security Info=False;"
        Dim sconInventory As New SqlCeConnection(strPath)
        
        Dim scmdInventory As New SqlCeCommand(strSql, sconInventory)
        Dim val1 As Integer()

        sconInventory.Open() 'This is the line telling me it can't find the database. Everything below is code I'll fix later 
        Dim sqlReader As SqlCeDataReader = scmdInventory.ExecuteReader()

        Try
            Dim i As Integer = 0
            While sqlReader.Read()
                val1(i) = sqlReader.GetInt32(0)
                i += 1
                MsgBox(val1(i) & " " & i)
            End While
        Finally
            sqlReader.Close()

            sconInventory.Close()

        End Try



        For i = 0 To val1.length - 1

        Next

    End Sub

Open in new window

Screenshot of the project
0
Comment
Question by:75THRGR
2 Comments
 
LVL 16

Accepted Solution

by:
hjgode earned 200 total points
ID: 35438541
Hello

windows ce based devices do not support a current directory. So it is best to ALWAYS provide full path information for every file you want to use.

Change your connect string and include the path to the sdf database file. For example
"Data Source = \Program Files\InventoryProject\AppDatabase1.sdf;"
instead of "Data Source = AppDatabase1.sdf;" only.

See also here: http://www.connectionstrings.com/sql-server-2005-ce
0
 

Author Closing Comment

by:75THRGR
ID: 35441018
That was it, wasn't sure what directory it was being ran from on the emulator, so you answered two questions in one. Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 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