DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
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
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
In witch line you get the error?
..
Where are you from?
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
hi, I get the error on :
It informs that the database file can't be found.
I am from Cyprus,studying in the uk :)
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
Well it's kinda obvious that you don't point to the correct location...
Gia sou file giorgo ;)
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
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.
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
"data source ="".\mydatabase.sdf;"""
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
if you are correct with the (")
here you write data source =".\mydatabase.sdf;"
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
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
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
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 =)
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
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 :) )
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
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
Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])
ok, I have found the answer.
vb Code:
Dim MyConnection As SqlCeConnection
Dim datalocation As String = "\Program Files\ApplicationName\MyDatabase.sdf"
MyConnection = New SqlCeConnection("Data Source=" & datalocation)
Thank you for your help :)