1

I have a local database, and of course it works on other devices but they have to add the data connection that comes with the project themselves (image for reference): Image of data connection in server explorer

I'm in a position where I need to add a new data connection like WorkerLogin.mdf in the above image, but cannot do so by simply navigating server explorer and manually adding it. Is there any way to do this on a form_load event for example or in any programming in VB. This is it for my coursework otherwise.

Thanks in advance for any comments and answers.

djv
  • 15,168
  • 7
  • 48
  • 72
SpakyDaky
  • 21
  • 3
  • If you're working with Microsoft SQL databases, take a look at the [https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient?view=dotnet-plat-ext-6.0] SqlClient library. With this you can create ADO connections to your database. – bPuhnk May 09 '22 at 18:35
  • No one needs to use Server Explorer, including you. That just gives you easy access to the database in the IDE in order to make schema or data changes. In code, you simply create a connection object, e.g. a `SqlConnection`, and provide an appropriate connection string. Where that connection string comes from is up to you. That's how it works after you deploy your app, even if you used Server Explore to build it. – John May 10 '22 at 02:08
  • Thank you both for replying, I found the link you included very useful and although it did not fully solve my problem it did show me my problem was deeper rooted. I also did not properly understand how to create the correct connection object, as I currently 'Dim conn As New SqlConnection' at the top of every form that uses 'Application.StartupPath' combined with the file name as it's string, is there a way I am missing? @John – SpakyDaky May 10 '22 at 10:02

0 Answers0