So I've got a little (and valid) .MDF
database file (SQL Server). However when I try to access it (line 32 here) or smaller context here...
private void loadDataBaseButton_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string databasePath = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
//SqlConnection dataBaseConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlConnection dataBaseConnection = new SqlConnection(string.Format(@"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Integrated Security=True;Connect Timeout=30;User Instance=True", databasePath));
try
{
dataBaseConnection.Open();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
However it throws an exception. Specifically it is an
Error 26 - Error Locating Server/Instance Specified
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/instance specified)
The .MDF
file is valid and everything else to my knowledge seems to check out. How do I fix this?