How do I give an SqlConnection a string as the AttachDbFilename?
How do I give an SqlConnection a string as the AttachDbFilename? I'd like to have a string be used as the AttachDbFilename in my SqlConnection . AttachDbFilename SqlConnection However when I feed it a string it doesn't work and just gives me a null or invalid connection/failure. How do I properly provide AttachDbFilename as a string value in place of the normal set path? AttachDbFilename DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { string databasePath = openFileDialog1.InitialDirectory + openFileDialog1.FileName; SqlConnection dataBaseConnection = new SqlConnection(@"Data Source=.SQLEXPRESS;AttachDbFilename=databasePath;Integrated Security=True;Connect Timeout=30;User Instance=True"); } 1 Answer 1 You have databasePath inside the string literal so right now you are trying to attach with a Db Filename of "databasePath", wh...
