0

My school project is in VisualStudio, there I have a local SQL Database. I will submit the project to teacher, but I connect SQL with this way:

SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\michalbrany\source\repos\CZU_projekt\zakaznickeudaje.mdf;Integrated Security=True;Connect Timeout=30");

Problem is, that my teacher will have downloaded the project to their Desktop, so this way will be incorrect. Can I use this?

SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=..\..\..\..\..\..\zakaznickeudaje.mdf;Integrated Security=True;Connect Timeout=30");

Or something else?

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • try it and you will know if you can do that or not. i would just use root folder instead of that 6 levels parent relative path – Steve Oct 21 '19 at 16:53
  • Taka a look at [this answer](https://stackoverflow.com/a/1409378) about using the `|DataDirectory|` substitution string in your connection string. – madreflection Oct 21 '19 at 17:22

1 Answers1

-1

Why not use a connection string pointing to the actual ip address or hostname of the server with the corresponding username and password? See connectionstrings.com where variation of connectionstrings can be found.

Hope this helps.

Ian Siñel
  • 95
  • 1
  • 11