0

I have a problem with the SqlConnection, the display can't open in Visual Studio

SqlConnection conn = new SqlConnection(@"D:\APLIKASI ALPEM\BISMILLAH\WINDOWSFORMSAPP1\LOGIN.MDF");
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
  • how did you get this string `D:\APLIKASI ALPEM\BISMILLAH\WINDOWSFORMSAPP1\LOGIN.MDF` – Saif Dec 06 '19 at 03:49
  • 1
    Does this answer your question? [How do I connect to an MDF database file?](https://stackoverflow.com/questions/8926512/how-do-i-connect-to-an-mdf-database-file) – Chetan Dec 06 '19 at 04:06

1 Answers1

0

Your path to database file contains space, so should be taken with double quotes at the beginning and the end. Try this:

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "DataSource=.\\SQLEXPRESS; AttachDbFilename=\"D:\\APLIKASI ALPEM\\BISMILLAH\\WINDOWSFORMSAPP1\\LOGIN.MDF\";Integrated Security=True;User Instance=True";
VillageTech
  • 1,968
  • 8
  • 18