473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

SQLServerCe connection string problems

markmcgookin
648 Expert 512MB
Hi Folks,

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

Expand|Select|Wrap|Line Numbers
  1. Data Source ="F:\Program Files(2)\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf";
  2.  
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:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlServerCe
  2.  
  3. Public Class Form1
  4.  
  5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Dim cn As SqlCeConnection
  7.         cn = New SqlCeConnection("Data Source ="F:\Program Files(2)\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf";)
  8.  
  9.     End Sub
  10. End Class
  11.  
  12.  
Thanks very much for your time.
Jan 29 '07 #1
4 7314
enreil
86
It looks like you are having trouble with the quotation marks in your connection string. Your code contains the line:

cn = New SqlCeConnection("Data Source ="F:\Program Files(2)\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf";)

You need to either use single quotation marks or escape the internal double quotation marks. I'd try the following first:

cn = New SqlCeConnection("Data Source ='F:\Program Files(2)\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf;'")

If the single quotes give you trouble (sorry, I haven't been able to test this myself), try:

cn = New SqlConnection("Data Source =""F:\Program Files(2)\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf;""")

Hopefully that'll put you on the right track.
Jan 29 '07 #2
enreil
86
Sorry about the wink - I guess that's what I get for using the ";" and the ")" characters together.
Jan 29 '07 #3
markmcgookin
648 Expert 512MB
Sorry about the wink - I guess that's what I get for using the ";" and the ")" characters together.
Hi I am considering changing and designing my application in visual studio 2003 and deploying it on a Pocket PC 2003 device instead of a Windows Mobile 5 Device. Simply because there is so much more documentation and reading material on it. Do you have any expertise in this area?

I would really like to have someone to chat to about this.

I am trying to design a program at the minute and am having real trouble connecting to SQL Server CE databases etc, and I would love someone to be able to show/send me a complete example of a working one so I could see it in action. The phrase I am using at the minute is "I am having trouble figuring out how to talk to the DB, once I get that sorted, I can figure out what to say myself!" hehe, if you understand what I mean? I think I can write mysql etc myself, but I can not seem to find anyone willing to show me a working VB/SQL Server CE program that I can look at and see where I am going wrong.

For example I am working through a book and have written this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class Form1
  3.  
  4.     Inherits System.Windows.Forms.Form
  5.     Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
  6.  
  7.  
  8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.  
  10.         Dim cn As SqlCeConnection
  11.  
  12.         Try
  13.             cn = New SqlCeConnection("Data Source=\\My Documents\\NorthwindDemo.sdf;password=")
  14.             cn.Open()
  15.  
  16.             Dim cmd As SqlCeCommand = cn.CreateCommand
  17.  
  18.             cmd.CommandText = "INSERT INTO Products (" & _
  19.                                         "ProductName, " & _
  20.                                         "SupplierID, " & _
  21.                                         "CategoryID, " & _
  22.                                         "UnitPrice, " & _
  23.                                         "UnitsInStock, " & _
  24.                                         "Discontinued, " & _
  25.                                         "VALUES " & _
  26.                                         "(?, ?, ?, ?, ?, ?)"
  27.  
  28.             cmd.Parameters.Add("@ProductName", "Axim")
  29.             cmd.Parameters.Add("@SupplierID", 1)
  30.             cmd.Parameters.Add("@CategoryID", 1)
  31.             cmd.Parameters.Add("@UnitPrice", 350)
  32.             cmd.Parameters.Add("@UnitsInStock", 20)
  33.             cmd.Parameters.Add("@Discontinued", 1)
  34.  
  35.             cmd.Prepare()
  36.             cmd.ExecuteNonQuery()
  37.  
  38.         Catch sqlex As SqlCeException
  39.             Dim sqlError As SqlCeError
  40.  
  41.             For Each sqlError In sqlex.Errors
  42.  
  43.                 MessageBox.Show(sqlError.Message)
  44.  
  45.             Next
  46.  
  47.         Catch ex As Exception
  48.             MessageBox.Show(ex.Message)
  49.  
  50.         Finally
  51.             If cn.State <> ConnectionState.Closed Then
  52.                 cn.Close()
  53.  
  54.             End If
  55.         End Try
  56.     End Sub
  57. End Class
  58.  
and keep getting an output in the Autos section at the bottom where "cmd" and "cn" are stuck with null values and some other errors. I think it has something to do with the location of the DB being in My Doc, but the book I am reading insists on it being there.
Jan 30 '07 #4
enreil
86
It looks like your connection string is giving you problems. You can stick your database anywhere you please - there's nothing special about it being in My Documents. Wherever you stick the Northwind DB, make sure you include the full path reference in your command string. For instance, if you place it in My Documents, make sure the path is as follows:

"C:\\Documents and Settings\\YOUR USERNAME\\My Documents\\Northwind.mdb"

You can check connectionstrings.com for further guidance (http://www.connectionstrings.com/) if this doesn't quite do it for you.

I haven't had any experience deploying to mobile devices - sorry, wish I could help you there.

Hi I am considering changing and designing my application in visual studio 2003 and deploying it on a Pocket PC 2003 device instead of a Windows Mobile 5 Device. Simply because there is so much more documentation and reading material on it. Do you have any expertise in this area?

I would really like to have someone to chat to about this.

I am trying to design a program at the minute and am having real trouble connecting to SQL Server CE databases etc, and I would love someone to be able to show/send me a complete example of a working one so I could see it in action. The phrase I am using at the minute is "I am having trouble figuring out how to talk to the DB, once I get that sorted, I can figure out what to say myself!" hehe, if you understand what I mean? I think I can write mysql etc myself, but I can not seem to find anyone willing to show me a working VB/SQL Server CE program that I can look at and see where I am going wrong.

For example I am working through a book and have written this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class Form1
  3.  
  4.     Inherits System.Windows.Forms.Form
  5.     Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
  6.  
  7.  
  8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.  
  10.         Dim cn As SqlCeConnection
  11.  
  12.         Try
  13.             cn = New SqlCeConnection("Data Source=\\My Documents\\NorthwindDemo.sdf;password=")
  14.             cn.Open()
  15.  
  16.             Dim cmd As SqlCeCommand = cn.CreateCommand
  17.  
  18.             cmd.CommandText = "INSERT INTO Products (" & _
  19.                                         "ProductName, " & _
  20.                                         "SupplierID, " & _
  21.                                         "CategoryID, " & _
  22.                                         "UnitPrice, " & _
  23.                                         "UnitsInStock, " & _
  24.                                         "Discontinued, " & _
  25.                                         "VALUES " & _
  26.                                         "(?, ?, ?, ?, ?, ?)"
  27.  
  28.             cmd.Parameters.Add("@ProductName", "Axim")
  29.             cmd.Parameters.Add("@SupplierID", 1)
  30.             cmd.Parameters.Add("@CategoryID", 1)
  31.             cmd.Parameters.Add("@UnitPrice", 350)
  32.             cmd.Parameters.Add("@UnitsInStock", 20)
  33.             cmd.Parameters.Add("@Discontinued", 1)
  34.  
  35.             cmd.Prepare()
  36.             cmd.ExecuteNonQuery()
  37.  
  38.         Catch sqlex As SqlCeException
  39.             Dim sqlError As SqlCeError
  40.  
  41.             For Each sqlError In sqlex.Errors
  42.  
  43.                 MessageBox.Show(sqlError.Message)
  44.  
  45.             Next
  46.  
  47.         Catch ex As Exception
  48.             MessageBox.Show(ex.Message)
  49.  
  50.         Finally
  51.             If cn.State <> ConnectionState.Closed Then
  52.                 cn.Close()
  53.  
  54.             End If
  55.         End Try
  56.     End Sub
  57. End Class
  58.  
and keep getting an output in the Autos section at the bottom where "cmd" and "cn" are stuck with null values and some other errors. I think it has something to do with the location of the DB being in My Doc, but the book I am reading insists on it being there.
Jan 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Andy Wawa | last post by:
Hi, on a simple HTML (not an ASP!)-Site I try to connect to a sql server (MS): <html> <title>Test</title> <head> <script language="javascript"> <!-- Function showForm(){
1
by: Cliff Cooley | last post by:
Can anybody suggest what may be causing the following problem ? I have an ASP script that opens a connection to an Oracle database using a DSN connection string, such as : Set dbConn=...
0
by: Bob | last post by:
I have an ASP.NET web application that has been running without any problems for a while. I recently transferred the site to shared hosting and had multiple users start to use the site. The problem...
5
by: Fred Zuckerman | last post by:
Hello All, After reading in this group about the preference for connecting to a SQL Server using a connection string instead of a DSN file, I have done just that. BUT, I cannot update my data....
9
by: mcbill20 | last post by:
Hello all. I just installed Oracle 10g developer tools on a machine running XP Pro and Office XP. Before this I had just the Oracle 9 client installed. I the previous configuration, I was able to...
0
by: gcrasher | last post by:
I have a business assembly that makes a reference to a CF assembly that uses SqlServerCe. Now I'm trying to write a simple webservice that references this business assembly but I am unable to...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
1
by: LitaOsiris | last post by:
Hi all, I'm getting the following error: The type 'System.Data.Common.DbConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data,...
2
by: sabitawoonna | last post by:
I developed 1 new project i.e workstation project.I have one sqlserverce database i.e workstationProject.sdf.In this database i have 2 tables i.e demolist,userinformation. In demolist i have 2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.