My C # course teacher taught a new technique for us today, one need not tell ConnectionString itself, the program would go to the documents folder and get the .mdf file (SQL Server) and open the connection with it, but I have the following error:
Herearemycodes:
stringx= Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); AppDomain.CurrentDomain.SetData("DataDirectory", x);
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 directory of the mdf file, which is picked up by the "DataDirectory".
I would like to know what happened, since when it was tested during the lesson, with the same codes, it worked.
(The .mdf file is in my "Documents" folder)