Through the Server Explorer, I'm able to test the connection, and a successful connection is made.
The connectionstring added to app.config was generated automatically, however when I try to open a sqlConnection, the connection seems to fail!?!?
The connectionstring declared in the Server Explorer is: "Data Source=D:\My Docs\Documents\Visual Studio 2008\Projects\POS\POS\Data\posDB.sdf" with the provider set to: ".NET Framework Data Provider for Microsoft SQL Server Compact 3.5".
The connectionstring in app.config is:
<connectionStrings>
<add name="POS.My.MySettings.posDBConnectionString"
connectionString="Data Source=|DataDirectory|\Data\posDB.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>
Retrieving the connectionstring through app.config using:
Dim dt As New DataTable
Dim sql As String = "SELECT * FROM Branch"
Using sqlCon As New SqlConnection(My.Settings.posDBConnectionString)
Using sqlCmd As New SqlCommand(sql, sqlCon)
Try
sqlCon.Open()
Dim sqlRdr As SqlDataReader = sqlCmd.ExecuteReader()
If sqlRdr.HasRows Then dt.Load(sqlRdr, LoadOption.PreserveChanges)
sqlRdr.Close()
Catch ex As Exception
result = False
End Try
End Using
End Using
causes an error at "sqlCon.Open()", I presume its the connectionstring as I've tried running the query (sql variable value at that point) directly in Server Explorer and that returned with no problems.
The value of "My.Settings.posDBConnectionString" returns "Data Source=|DataDirectory|\Data\posDB.sdf". The exception I'm getting complains "A network-related or instance-specific error occurred while establishing a connection to SQL Server"?!?
Any ideas?
Any help would be greatly appreciated.
Thanks.
The connectionstring added to app.config was generated automatically, however when I try to open a sqlConnection, the connection seems to fail!?!?
The connectionstring declared in the Server Explorer is: "Data Source=D:\My Docs\Documents\Visual Studio 2008\Projects\POS\POS\Data\posDB.sdf" with the provider set to: ".NET Framework Data Provider for Microsoft SQL Server Compact 3.5".
The connectionstring in app.config is:
<connectionStrings>
<add name="POS.My.MySettings.posDBConnectionString"
connectionString="Data Source=|DataDirectory|\Data\posDB.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>
Retrieving the connectionstring through app.config using:
Dim dt As New DataTable
Dim sql As String = "SELECT * FROM Branch"
Using sqlCon As New SqlConnection(My.Settings.posDBConnectionString)
Using sqlCmd As New SqlCommand(sql, sqlCon)
Try
sqlCon.Open()
Dim sqlRdr As SqlDataReader = sqlCmd.ExecuteReader()
If sqlRdr.HasRows Then dt.Load(sqlRdr, LoadOption.PreserveChanges)
sqlRdr.Close()
Catch ex As Exception
result = False
End Try
End Using
End Using
causes an error at "sqlCon.Open()", I presume its the connectionstring as I've tried running the query (sql variable value at that point) directly in Server Explorer and that returned with no problems.
The value of "My.Settings.posDBConnectionString" returns "Data Source=|DataDirectory|\Data\posDB.sdf". The exception I'm getting complains "A network-related or instance-specific error occurred while establishing a connection to SQL Server"?!?
Any ideas?
Any help would be greatly appreciated.
Thanks.