Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Connecting to a c# Local Database

Connecting to a c# Local Database

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadmin
12 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Grose
    wrote on last edited by
    #1

    I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D

    T L F L 4 Replies Last reply
    0
    • A Alex Grose

      I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D

      T Offline
      T Offline
      TALHAKOSEN
      wrote on last edited by
      #2

      you should use Data class of framework. Using data; SqlConnection dataConn = new SqlConnection();, dataConn.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;" dataconn.open(); after this time u ll have a data conn what db you wrote there. Then time you should search what you wanna want.

      thanks for everything i have...

      A 2 Replies Last reply
      0
      • T TALHAKOSEN

        you should use Data class of framework. Using data; SqlConnection dataConn = new SqlConnection();, dataConn.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;" dataconn.open(); after this time u ll have a data conn what db you wrote there. Then time you should search what you wanna want.

        thanks for everything i have...

        A Offline
        A Offline
        Alex Grose
        wrote on last edited by
        #3

        Sorry, I have tried to connect using this method, the file is called Register.sdf and is in the same directory as the project content. This code fails to load the database effectively. This is the code I am trying to use (The 'Global' Class is a static class containing the RegDB Variable)

        private bool loadDatabase() {
        Global.RegDB = new SqlConnection();
        Global.RegDB.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;";
        try {
        Global.RegDB.Open();
        return true;
        }
        catch {
        return false;
        }
        }

        1 Reply Last reply
        0
        • T TALHAKOSEN

          you should use Data class of framework. Using data; SqlConnection dataConn = new SqlConnection();, dataConn.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;" dataconn.open(); after this time u ll have a data conn what db you wrote there. Then time you should search what you wanna want.

          thanks for everything i have...

          A Offline
          A Offline
          Alex Grose
          wrote on last edited by
          #4

          TALHAKOSEN wrote:

          did you take an error like below TITLE: Connect to Server ------------------------------ Cannot connect to C:\DEV\SyncServices\learning\ConsoleSync1\ConsoleSync1\bin\Debug\awclientdb.sdf. ------------------------------ ADDITIONAL INFORMATION: You are trying to access an older version of a SQL Server Compact Edition database. If this is a SQL Server CE 1.0 or 2.0 database, run upgrade.exe. If this is a SQL Server Compact Edition 3.0 or later database, run Compact / Repair. [ Db version = 3505053,Requested version = 3004180,File name = C:\DEV\SyncServices\learning\ConsoleSync1\ConsoleSync1\bin\Debug\awclientdb.sdf ] (SQL Server Compact Edition ADO.NET Data Provider) ------------------------------ BUTTONS: OK

          No, the function just failed in the try block and then returned false in the catch block

          1 Reply Last reply
          0
          • A Alex Grose

            I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D

            L Offline
            L Offline
            leckey 0
            wrote on last edited by
            #5

            http://connectionstrings.com/[^] Is anyone else getting sick of this basic question?!?

            Blog link to be reinstated at a later date.

            A P 2 Replies Last reply
            0
            • L leckey 0

              http://connectionstrings.com/[^] Is anyone else getting sick of this basic question?!?

              Blog link to be reinstated at a later date.

              A Offline
              A Offline
              Alex Grose
              wrote on last edited by
              #6

              No, I don't think that I have explained myself correctly. I want to be able to access the database file as if it were a database, but without running SQL server. I plan to move the program to another machine that is not running SQL server.

              M M 2 Replies Last reply
              0
              • A Alex Grose

                No, I don't think that I have explained myself correctly. I want to be able to access the database file as if it were a database, but without running SQL server. I plan to move the program to another machine that is not running SQL server.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                You can't use a SQL Server database without SQL Server AFAIK. SQL Server doesn't come built-in to the .NET framework. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                1 Reply Last reply
                0
                • A Alex Grose

                  No, I don't think that I have explained myself correctly. I want to be able to access the database file as if it were a database, but without running SQL server. I plan to move the program to another machine that is not running SQL server.

                  M Offline
                  M Offline
                  Malcolm Smart
                  wrote on last edited by
                  #8

                  Isn't that like trying to open an MS Excel document without Microsoft Excel? I imagine, if you want, you could open the SDF as a text file and have a look inside, but it won't act as a database without a database server. The clue is in the name - server. It 'serves' the data. The fact that the underlying datastore is a file is irrelevant.

                  Knowledge is hereditary, it will find its way up or down. Luc Pattyn
                  and since what every time when i want to add button to this control one add two times posted in C# forum

                  A 1 Reply Last reply
                  0
                  • A Alex Grose

                    I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D

                    F Offline
                    F Offline
                    funklet
                    wrote on last edited by
                    #9

                    Right Click your project in Solution Explorer, Add / Component / SQL Database You can then use the database as a file in your project. Kind Regards.

                    1 Reply Last reply
                    0
                    • M Malcolm Smart

                      Isn't that like trying to open an MS Excel document without Microsoft Excel? I imagine, if you want, you could open the SDF as a text file and have a look inside, but it won't act as a database without a database server. The clue is in the name - server. It 'serves' the data. The fact that the underlying datastore is a file is irrelevant.

                      Knowledge is hereditary, it will find its way up or down. Luc Pattyn
                      and since what every time when i want to add button to this control one add two times posted in C# forum

                      A Offline
                      A Offline
                      Alex Grose
                      wrote on last edited by
                      #10

                      Ok, Thanks. I will investigate using SQLite as I have haerd that that can be used without a server (I.E Integrated) Thanks anyway.

                      1 Reply Last reply
                      0
                      • L leckey 0

                        http://connectionstrings.com/[^] Is anyone else getting sick of this basic question?!?

                        Blog link to be reinstated at a later date.

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #11

                        My Paranoid Hubby wrote:

                        anyone else getting sick of this basic question?

                        Yes, which is why I generally ignore them.

                        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                        1 Reply Last reply
                        0
                        • A Alex Grose

                          I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Well, it sounds like you are using SQL Server Compact Edition 3.5, which means SqlConnection is not what you want. You need to use the System.Data.SqlServerCe[^] namespace. There are a lot of samples out there just for that, like this one[^].

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups