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. access to localdb from different pcs in a lan network

access to localdb from different pcs in a lan network

Scheduled Pinned Locked Moved C#
csharpdatabasesysadminhelpquestion
14 Posts 4 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.
  • U Offline
    U Offline
    User 11862976
    wrote on last edited by
    #1

    Hello everyone, is there anyone who could help me on this? I create a c# application with localdb and i want to have access in this database from different pc in my network, eg i have a secretary with her pc and me with another and i want to use my application from my computer and the changes i have done in database i want to see my partner in her pc. I search for this subject in different forums but nothing. Sorry for my bad english.

    OriginalGriffO G L 3 Replies Last reply
    0
    • U User 11862976

      Hello everyone, is there anyone who could help me on this? I create a c# application with localdb and i want to have access in this database from different pc in my network, eg i have a secretary with her pc and me with another and i want to use my application from my computer and the changes i have done in database i want to see my partner in her pc. I search for this subject in different forums but nothing. Sorry for my bad english.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      The main change you need to make is to your connections string: make sure you load it from a configuration file of some description (along with your other parameters) and you can use a LOCALDB one from your machine, and a IP based or Server name based address from the other. Then it's up to you and how you code your app to "notice" changes if you want existing displays on the secretarial machine to update because of changes you make to the DB on yours. there are a lot of different ways to do that, but they all add a layer of complication so think carefully before you go down that route unless you need it.

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      U 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        The main change you need to make is to your connections string: make sure you load it from a configuration file of some description (along with your other parameters) and you can use a LOCALDB one from your machine, and a IP based or Server name based address from the other. Then it's up to you and how you code your app to "notice" changes if you want existing displays on the secretarial machine to update because of changes you make to the DB on yours. there are a lot of different ways to do that, but they all add a layer of complication so think carefully before you go down that route unless you need it.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        U Offline
        U Offline
        User 11862976
        wrote on last edited by
        #3

        First of all thank you for your reply. I have done this and i cant access to db, if i change the connection string from configuration file then throw exception error 52. I copy a shortcat from server to client and the result is the application starts but throw an exception with this error 52

        OriginalGriffO 1 Reply Last reply
        0
        • U User 11862976

          First of all thank you for your reply. I have done this and i cant access to db, if i change the connection string from configuration file then throw exception error 52. I copy a shortcat from server to client and the result is the application starts but throw an exception with this error 52

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Check that your SQL Server instance is configured to accept remote connections, and that the port it is using is unblocked in your firewall. If that doesn't fix it, start looking at the entire error message - it may contain further information.

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          U 1 Reply Last reply
          0
          • U User 11862976

            Hello everyone, is there anyone who could help me on this? I create a c# application with localdb and i want to have access in this database from different pc in my network, eg i have a secretary with her pc and me with another and i want to use my application from my computer and the changes i have done in database i want to see my partner in her pc. I search for this subject in different forums but nothing. Sorry for my bad english.

            G Offline
            G Offline
            Gilbert Consellado
            wrote on last edited by
            #5

            I assumed that you are using the local file .mdf. But if you are planning to access you data in the network, why not use the database server rather than using a file shortcut.

            U 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Check that your SQL Server instance is configured to accept remote connections, and that the port it is using is unblocked in your firewall. If that doesn't fix it, start looking at the entire error message - it may contain further information.

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              U Offline
              U Offline
              User 11862976
              wrote on last edited by
              #6

              If i understand correctly you tell me to use SQL Server Configuration Manager and from there enable tcp/ip but if you remember i use localdb in my project so no sql server express installed in these two computers. Should i install sql server express on computers i want use my application to do this? Thank you for you help and sorry bothering you!!!

              OriginalGriffO 1 Reply Last reply
              0
              • G Gilbert Consellado

                I assumed that you are using the local file .mdf. But if you are planning to access you data in the network, why not use the database server rather than using a file shortcut.

                U Offline
                U Offline
                User 11862976
                wrote on last edited by
                #7

                Hello Gilbert, could you tell me what did you mean step by step because i have no experience. I thought that if i use localdb i can't use database server to do what i want thus i use the shortcut instead. Thank you in advance

                G 1 Reply Last reply
                0
                • U User 11862976

                  If i understand correctly you tell me to use SQL Server Configuration Manager and from there enable tcp/ip but if you remember i use localdb in my project so no sql server express installed in these two computers. Should i install sql server express on computers i want use my application to do this? Thank you for you help and sorry bothering you!!!

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  If you mean you ar eusing Access or similar, then that's a poor idea (and don't call that "localdb" in future - that's often used for an SQL Server instance name). Access is a very poor multiuser database - it can work, but it has always given massive problems because it is intended to be a single user system, and local caching and suchlike can really, really mess your code and data up. If you need multiple users (or even multiple applications) accessing your data, then you really need to switch to a multiuser system, such as SQL Server or MySql - they "wrap around" an access DB and provide multiuser access seamlessly. I'd suggest SQL Server - there is a free version called Sql Server Express - and two instances: one on the secretaries machine (or better on a third machine) and a separate one on your development machine, so you can change and text your code without risking damaging the "production" database. Nothing, but nothing is as mortifying as discovering that you forgot the WHERE clause in an UPDATE or DELETE and having to explain you just elephanted someone else's whole day's work... :-O If you have written your code well, it's a simple change that shouldn't take very long: new connection string in the config file, and change the OdbcConnection, OdbcCommand and suchlike objects to their SqlConnection, SqlCommand, etc. equivalents will be 95% of it.

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  U 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    If you mean you ar eusing Access or similar, then that's a poor idea (and don't call that "localdb" in future - that's often used for an SQL Server instance name). Access is a very poor multiuser database - it can work, but it has always given massive problems because it is intended to be a single user system, and local caching and suchlike can really, really mess your code and data up. If you need multiple users (or even multiple applications) accessing your data, then you really need to switch to a multiuser system, such as SQL Server or MySql - they "wrap around" an access DB and provide multiuser access seamlessly. I'd suggest SQL Server - there is a free version called Sql Server Express - and two instances: one on the secretaries machine (or better on a third machine) and a separate one on your development machine, so you can change and text your code without risking damaging the "production" database. Nothing, but nothing is as mortifying as discovering that you forgot the WHERE clause in an UPDATE or DELETE and having to explain you just elephanted someone else's whole day's work... :-O If you have written your code well, it's a simple change that shouldn't take very long: new connection string in the config file, and change the OdbcConnection, OdbcCommand and suchlike objects to their SqlConnection, SqlCommand, etc. equivalents will be 95% of it.

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                    U Offline
                    U Offline
                    User 11862976
                    wrote on last edited by
                    #9

                    i use sql server express localdb. This is the connection string i used: connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\mydb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" (this is from app.config). What changes must do here? Realy big sorry for bothering you but i need your help! I try this and did not work: In the "third machine" i open the configuration file and use this connection string -> connectionString="Data Source=192.168.1.44;AttachDbFilename=|DataDirectory|\mydb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" Where is the problem? Thank you friend for your time

                    OriginalGriffO 1 Reply Last reply
                    0
                    • U User 11862976

                      i use sql server express localdb. This is the connection string i used: connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\mydb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" (this is from app.config). What changes must do here? Realy big sorry for bothering you but i need your help! I try this and did not work: In the "third machine" i open the configuration file and use this connection string -> connectionString="Data Source=192.168.1.44;AttachDbFilename=|DataDirectory|\mydb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" Where is the problem? Thank you friend for your time

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #10

                      Start SSMS, and it begins with a "connect to Server" dialog - look at the "Server name:" box. In my case, that would be "GRIFFPC\SQLEXPRESS" That is your server instance name, and that is what you want to use in the other PC. Now start VS and try setting up a connection in VS with the Server Explorer pane: 1) Open Server Explorer. 2) Right click "Data connections" and select "Add connection" 3) In the dialog that follows, select your DataSource (the name from above) and database, specify the security info, and press the "Test connection" button. 4) When the connection works, press "OK" 5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file. But seriously, it is a bad idea to use the same instance of SQL server for "production" and "development" - it never ends well.

                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      U 1 Reply Last reply
                      0
                      • U User 11862976

                        Hello everyone, is there anyone who could help me on this? I create a c# application with localdb and i want to have access in this database from different pc in my network, eg i have a secretary with her pc and me with another and i want to use my application from my computer and the changes i have done in database i want to see my partner in her pc. I search for this subject in different forums but nothing. Sorry for my bad english.

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

                        LocalDb; Sql Express, but locally, and will not accept remote connections. http://stackoverflow.com/questions/9193746/can-sql-server-express-localdb-be-connected-to-remotely[^] Install Sql Express.

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                        1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          Start SSMS, and it begins with a "connect to Server" dialog - look at the "Server name:" box. In my case, that would be "GRIFFPC\SQLEXPRESS" That is your server instance name, and that is what you want to use in the other PC. Now start VS and try setting up a connection in VS with the Server Explorer pane: 1) Open Server Explorer. 2) Right click "Data connections" and select "Add connection" 3) In the dialog that follows, select your DataSource (the name from above) and database, specify the security info, and press the "Test connection" button. 4) When the connection works, press "OK" 5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file. But seriously, it is a bad idea to use the same instance of SQL server for "production" and "development" - it never ends well.

                          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                          U Offline
                          U Offline
                          User 11862976
                          wrote on last edited by
                          #12

                          Thank you very much for your help. What do you suggest me to do if this is not good idea (i refer to: "But seriously, it is a bad idea to use the same instance of SQL server for "production" and "development" - it never ends well.")? WHAT would you do in my case?

                          OriginalGriffO 1 Reply Last reply
                          0
                          • U User 11862976

                            Thank you very much for your help. What do you suggest me to do if this is not good idea (i refer to: "But seriously, it is a bad idea to use the same instance of SQL server for "production" and "development" - it never ends well.")? WHAT would you do in my case?

                            OriginalGriffO Offline
                            OriginalGriffO Offline
                            OriginalGriff
                            wrote on last edited by
                            #13

                            Install a second instance of SQL Server express on a different computer: either the secretaries or (better) a server if you have one. Because your connection string should be in a config file rather than hard-coded into your app, it's easy to have different config files for your PC - one for production, one for development. And it should be on a computer that is backed up regularly, so that the DB is also backed up. (I'm betting that you never find the time to back up your dev PC, but that's the one at most risk from accidental damage - it's far, far too easy to make mistakes!) Once data gets to the "production" status - and if someone else is using it, that counts - you start risking a lot of embarrassment as well as significant damage to other people's work.

                            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                            1 Reply Last reply
                            0
                            • U User 11862976

                              Hello Gilbert, could you tell me what did you mean step by step because i have no experience. I thought that if i use localdb i can't use database server to do what i want thus i use the shortcut instead. Thank you in advance

                              G Offline
                              G Offline
                              Gilbert Consellado
                              wrote on last edited by
                              #14

                              A quick search on google can give a lot of information. I hope this link can give you a head start How to: Create Connections to SQL Server Databases

                              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