I am having some trouble with a connection to a database in Visual Studio 2005, I have managed to add the Northwind.sdf demo database to my "server explorer" window in VS and in the properties window, the connection string
Data Source ="F:\Program Files(2)\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf";
appears, but when I go to paste it into my code, the "Data Source" bit is hi-lighted in red, as is the trailing " ; ) I am unfortunatly working from a VB .Net SQLServer CE book, and this is Visual Studio 2005, so there must be some changes that I don't know about.
Mousing over the "F:" bit which is underline in squiggley blue gives this error:
"Comma, ')', or a valid expression continuation expected"
Then mousing over the "\" gives
"Syntax Error"
I don't know if VS2005 means I don't have to declare all this as it is already in the Server Explorer window, but I'd really appreciate some help, as I am totally stuck here. Some relevant websites would also be helpful, I am finding it a real hard time to get any decent ones outside of Microsoft, which isn't great at explaining stuff.
The code is as follows:
Imports System.Data.SqlServerCe
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As SqlCeConnection
cn = New SqlCeConnection("Data Source ="F:\Program Files(2)\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf";)
End Sub
End Class
Thanks very much for your time.

Connection String with Northwind demo Problems
ahmed_ieee
I'm not sure I am quite with you, but I think I will explain a bit better, I am creating an application that I want to access data stored in a database on the pda, Ideally the ability to update the database etc, with SQL functions, however I don't want it to sync up with any other database or anything (just a means of storing an amount of static data). I have copied the test .sdf file into my documents now, and have tried this
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As SqlCeConnection
cn = New SqlCeConnection()
cn.ConnectionString = "Data Source=\\My Documents\\Northwind.sdf";Password="
cn.Open()
I really just want to know how to open a connection to a database, It will be deployed to a PDA or an Emulator, but I haven't even got that far, as I can't seem to get this connection string to work.
erikkl2000
If you look inside your connection string you'll find unescaped and unmatched quote inside so it should not even compile.
Next, if you intended to run it on device (and if you’re not you’re in a wrong forum) it's not going to work even if you managed to fix syntax error and compile. See this on why is that.
TheJet
I ended up paying a freelance computist to build me an app, it took her about 2hrs and she gave me excellent annotated code and provided more functions than I asked for. I will happily share the code with others in this situation. It was just SO hard to find an application that was simple and you could just copy and paste some code in to see one working and talking to a DB, something that I personally believe should be incredibly simple.
(NB The programmer actually provided a code that created the database in stages, thus reducing complications of moving a DB accross from my PC, so there wasn't even a need to send a .sdf file)
Yousef ED
I have tried editing the code and I am sure that I have some form of connection to the database, as it is being deployed (although that would mean that I simply included it correctly in the properties as content)
I know this is a REALLY long shot, and I know that this is not what these forums are for, but would someone be able to design me a shell/smaple database that works, like 2 tables This is not what I would be using, but having one working would be amazing! I could actually see what is happening and see the format and syntax of the code, that actually works and converse with someone about it.
e.g -
tbl_first(prod_id, prod_name)
tbl_second(description, prod_id)
with like a few lines of data and a dropdown that say displays the prod_names, and when you select a name, the prog would match up with the prod_id, match it to the other table, and display the description.
I'm sorry, and I know this is not what these forums are for, but I am just starting the design phases of my final year project in university and I havent been taught ANY VB/SQLserverCe. but have to do it for my project as it needs to involve new learning. Having never seen a working version of this it is causing me so much stress, as I don't even have something to look at to compare my problems to.
I hope some of you have been in a similar boat at some point and can relate to how hard this kind of situation is when you can not find anyone to help you with a project, if someone is willing to do it for free that would be amazing, someone with skills in this area will hopefully find it very simple, if someone would do it, but for money, I don't have much being a student, but would be willing to negotiate something to have some help here.
If anyone would be willing to help I would greatly appreciate it.
Gary Burghardt
That should work if you:
1. Get rid of C# escaped double slashes as you're using VB.
2. Get rid of nested quote as it would result in syntax error.
3. You've copied database to the device's "My Documents", not desktop's and location is correct.
Something like this:
cn.ConnectionString = "Data Source=\My Documents\Northwind.sdf”
Normally you should add database to your project and configure it to be deployed on to device by VS. You might want to check out this walkthrough.
Mason Cox
check with this link http://msdn2.microsoft.com/en-us/library/aa454904.aspx#ui_data_designers_netcf2_topic9, may be i can help you.