1
My C# teacher taught us a new technique today, one does not need to inform Connectionstring itself, the program would go to the document folder and pick up the file . mdf (SQL Server) and open the connection with it, but I have been presenting the following error:
These are my codes:
- I went to the Program.Cs file in Visual Studio and added the following lines:
string x = Environment.Getfolderpath(Environment.SpecialFolder.Mydocuments); AppDomain.CurrentDomain.SetData("DataDirectory", x);
- In the class that stores Connectionstring, I put the following line:
public Static string Connectionstring = @"Data Source=(Localdb) v11.0;Attachdbfilename=|Datadirectory|/baseFarmaciaZyX.mdf;Integrated Security=True;Connect Timeout=30";
The bold part would be the mdf file directory, which is picked up by "Datadirectory".
I’d like to know what happened, since when you were tested during class with the same codes, it worked.
(The file . mdf is in my folder "Documents")