On Visual Studio 2010, I have a database that I'm trying to connect to, but when I try to do:
db.Open();
It launches this mistake:
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)
I tried to do what this link says, but I still keep having the same mistake.
Any ideas on what's going on?
EDIT: Firewall is OFF.
Connection String: MySQLProject.Properties.Settings.Default.dbConnectionString = "Data Source=|DataDirectory|\db.sdf"
Server is up:
EDIT2:
This is the code that fails:
public void FillData()
{
// 1 step. Open connection
// SqlConnection c = new SqlConnection("Data Source=" +db.Connection.DataSource);
SqlConnection c = new SqlConnection(MySQLProject.Properties.Settings.Default.dbConnectionString);
try
{
c.Open();
// 2 step. Create new DataAdapter
using (SqlDataAdapter a = new SqlDataAdapter("SELECT * FROM USER", c))
{
// 3 step. Use DataAdapter to fill table
DataTable t = new DataTable();
a.Fill(t);
// 4 step. Render data on the DataGridView
dataGridViewUsers.DataSource = t;
}
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
}
EDIT nº 1000:
Ok, I used this connection string:
string con2 = @"Server=.\SQLExpress;AttachDbFilename=|DataDirectory|db.sdf;Database=db;Trusted_Connection=Yes;";
And then it says this:
:____(
Ok, now i Know that .sdf
is for CE Sql statements. But, I can't create .mdf
, don't know exactly why... Should I change to CE Sql statements?