PDA

Click to See Complete Forum and Search --> : DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])


Sgiorgos
Sep 13th, 2007, 03:36 AM
Hi,
I am currently developing an application using vb.net 2005 and windows mobile 6 sdk,and sql server ce for my database.

I try to connect to the database i created using the following code: I get an identifier expected error
pointing the dot[.] .The code is this ("Data Source =".\ MyDatabase.sdf;"")

Visual Basic.Net 2005. The whole class is the following:

Dim conn As SqlCeConnection = Nothing

Try
conn = New SqlCeConnection("Data Source =".\ MyDatabase.sdf;"")
conn.Open()

Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandText = "INSERT INTO Customers (Customerid], Name) Values('9', 'Smith')"

cmd.ExecuteNonQuery()
Finally
conn.Close()
End Try

sapator
Sep 13th, 2007, 04:03 AM
In witch line you get the error?
..
Where are you from?

Sgiorgos
Sep 13th, 2007, 04:45 AM
hi, I get the error on :

conn.Open()

It informs that the database file can't be found.

I am from Cyprus,studying in the uk :)

sapator
Sep 13th, 2007, 05:12 AM
Well it's kinda obvious that you don't point to the correct location...
Gia sou file giorgo ;)

Sgiorgos
Sep 13th, 2007, 06:03 AM
Geia sou pali ,

The problem is not this as i get the connection string from vb.net itself.

I have uploaded screen shots of the error i get.

www.paphos.ws/vbnet

sapator
Sep 13th, 2007, 06:28 AM
"data source ="".\mydatabase.sdf;"""

sapator
Sep 13th, 2007, 06:33 AM
if you are correct with the (")
here you write data source =".\mydatabase.sdf;"

petevick
Sep 13th, 2007, 07:35 AM
Hi,
surely it should be
Try
conn = New SqlCeConnection("Data Source=\MyDatabase.sdf")
conn.Open()

or
conn = New SqlCeConnection("Data Source=\My Documents\MyDatabase.sdf")

Pete

Sgiorgos
Sep 13th, 2007, 09:16 AM
Unfortunately none of the solutions work .

Could somebody rewrite and test the application on his vb.net?

and email me the zip file containing the code and the sdf file.

It would be greatly appreciated . Thank you =)

sapator
Sep 13th, 2007, 09:21 AM
Explain what the problem is and we will try to help you.
Check your solution in a windowsapplication also to see if you are doing it correctly.


(ela mi variesai :) )

petevick
Sep 13th, 2007, 10:09 AM
The screenshots you posted explain EXACTLY what your problem is - missing identifier.
In which folder on the device is your database - your connection string needs to point to that folder.

Look at your connection string carefully - that is where your problem lies.

You have been given the correct solution already.

Pete

Sgiorgos
Sep 17th, 2007, 01:25 PM
ok, I have found the answer.

Dim MyConnection As SqlCeConnection

Dim datalocation As String = "\Program Files\ApplicationName\MyDatabase.sdf"

MyConnection = New SqlCeConnection("Data Source=" & datalocation)




Thank you for your help :)