Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7022911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:38:35+00:00 2026-05-27T23:38:35+00:00

I am working with a SQL compact database and I am able to test

  • 0

I am working with a SQL compact database and I am able to test the connection when I import it and copy the exact file path to my code, but it still says that it hasn’t been opened. What am I doing wrong? Are there any shortcuts available if I have already added the database to my project?

Thanks!

Imports System.Data.SqlServerCe 

Module Module1

Sub Main()

    Dim constring As String = "Data Source=C:\Users\test\Desktop\MyDatabase1.sdf"

    Dim conn As New SqlCeConnection(constring)

    Dim cmd As New SqlCeCommand("SELECT * FROM ACCOUNT")

    conn.Open()

    Dim reader As SqlCeDataReader = cmd.ExecuteReader()

    While reader.Read()
        Console.WriteLine(reader)
    End While


End Sub

End Module
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:38:36+00:00Added an answer on May 27, 2026 at 11:38 pm

    You need to assign the connection to the command:

    Immediately after this line:

    conn.Open()
    

    add:

    cmd.Connection = conn
    

    Alternatively, you can add the connection to the command’s constructor:

    Dim cmd As New SqlCeCommand("SELECT * FROM ACCOUNT", conn)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a program working with a database I created using SQL Server Compact
Hi Im currently working with .sdf database (Server Compact Version 4.0) and sql express.
I have a windows application working with a SQL Compact 4.0 database, using EF
I'm working on a Windows Mobile 6.5 application that uses a SQL compact database
I'm working with SQL Server database; database instance encoding is SQL_Latin1_General_CP1_CI_AS. The following code:
I am working on sql server where i want to save html code into
I am working with SQL Server and I want to set the Database password
I am working on defining a sql query for use in sql server compact
I am using the Entity Framework and SQL Server Compact Edition through the code
I'm working on SQL Compact 3.5 (Microsoft). Is something like this possible? ::- ).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.