I'm trying to learn VB and have written a program to choose a restaurant. I'm using Microsoft Visual Basic 2010 Express and the DB is SQL Server Compact 3.5. the program is a Windows Form application. The user chooses a series of options and then clicks a button. On buttonclick a SQL query is generated based on their choices. I'm having a problem returning my results in a datagridview.
The error I'm getting is " Unknown connection option in connection string: .net framework data provider for microsoft sql server compact 3.5data source." The relevant code is:
Dim conAsNew SqlServerCe.SqlCeConnection
Dim dbProvider AsString
Dim dbSource AsString
Dim ds As NewDataSet
Dim da As SqlServerCe.SqlCeDataAdapter
dbProvider = ".NET Framework Data Provider for Microsoft SQL Server Compact 3.5"
dbSource = "Data Source = C:\Users\mkg\Documents\Visual Studio 2010\Projects\vbLunch\WindowsApplication1\Restaurants.sdf"
con.ConnectionString = dbProvider & dbSource
con.Open()
da = New SqlServerCe.SqlCeDataAdapter(conditions, con)
da.Fill(ds, "Pick")
I'm fairly sure that both the dbprovider and dbsource are correct - I got the provider from the properties of the DB and I've verified the path to the DB, so I have no idea what's wrong. "Conditions" is the sql query that is generated based on the user's choices. I know the query is formatted correctly because I was able to test that using a MsgBox. On the form, the datagridview's datasource is set to UseThisOne.Restaurants.Fill,GetData(). It does return results if I Preview it.
Hopefully I've provided enough info but I'll be happy to update my question if I've missed anything.
Here's the full error message:
System.ArgumentException was unhandled
Message=Unknown connection option in connection string: .net framework data provider for microsoft sql server compact 3.5data source.
Source=System.Data.SqlServerCe
StackTrace:
at System.Data.SqlServerCe.ConStringUtil.ParseStringIntoHashtable(String conString, Hashtable values)
at System.Data.SqlServerCe.ConStringUtil.ParseConnectionString(String& connectionString)
at System.Data.SqlServerCe.SqlCeConnection.set_ConnectionString(String value)
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\mkg\documents\visual studio 2010\Projects\vbLunch\WindowsApplication1\Form1.vb:line 104
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: