Error SQL Server does not exist or access denied how to handle ?
This error while writing his OLEDB connection to sql, sql user and the window are not to be .
Use SQLOLEDB, slqncli have not been .
Please any help !
// Create a connection string:
string connectionString = "Provider = sqloledb; server = (local)\\sqlexpress; database = qlsinhvien; uid = [Removed]; pwd = [Removed] ;integrated security = sspi";
// Create OleDbConnection object to connect to the database: qlsinhvien:
OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);
// Create OleDbCommand object and connect to the myOleDbConnection:
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();
// set the CommandType property of the OleDbCommand object to TableDirect:
myOleDbCommand.CommandType = CommandType.TableDirect;
try
{
myOleDbConnection.Open();
MessageBox.Show("Connection opened.");
// Set the CommandText property of the OleDbCommand object to
// the name of the table to retrieve from:
myOleDbCommand.CommandText = "sinh_vien";
// Create OleDbDataReader object for the ExecuteReader() method:
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
// Only read the first 3 rows from the OleDbDataReader object:
StringBuilder sb = new StringBuilder();
for (int count = 1; count <= 3; count++)
{
myOleDbDataReader.Read();
sb.AppendLine("myOleDbDataReader[\"ma_sinh_vien\"> = " + myOleDbDataReader["ma_sinh_vien">);
sb.AppendLine("myOleDbDataReader[\"ten_sinh_vien\"> = " + myOleDbDataReader["ten_sinh_vien">);
sb.AppendLine("myOleDbDataReader[\"hoc_bong\"> = " + myOleDbDataReader["hoc_bong">);
sb.AppendLine();
}
myOleDbDataReader.Close();
MessageBox.Show("OleDbDataReader closed.");
MessageBox.Show(sb.ToString());
}
catch (OleDbException ex)
{
MessageBox.Show("Connection not found: " + ex.Message, "Error");
}
catch (Exception ex)
{
MessageBox.Show("Another error: " + ex.Message, "Error");
}
finally
{
myOleDbConnection.Close();
MessageBox.Show("Connection closed.");
}-
Hello :) Your access level is listed as "Website Owner". Have you reported this issue to your web hosting provider and verified it's supported? The output suggests the connection is not intended for MySQL. Thank you. 0
Please sign in to leave a comment.
Comments
1 comment