Reputation: 1214
I am trying to connect to SQL Server with OledbConnection but its showing error
Server does not exist or access denied
My code is
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
try
{
// test the connection with an open attempt
conn.Open();
this.Dispose();
}
catch (Exception ex)
{
// inform the user if the connection was not saved
MessageBox.Show(ex.Message, "Connection Test");
}
}
Upvotes: 0
Views: 2373
Reputation: 263723
Here are list of available connection string for MSSQL Server. Much better if you use System.Date.SqlClient namespace.
Using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open()
// do something here
}
catch (SqlException ex)
{
}
finally
{
connection.Close()
}
}
Upvotes: 1