Leader2000
Messages postés184Date d'inscriptionmercredi 24 mai 2006StatutMembreDernière intervention28 août 2015
-
5 juil. 2013 à 15:07
Leader2000
Messages postés184Date d'inscriptionmercredi 24 mai 2006StatutMembreDernière intervention28 août 2015
-
5 juil. 2013 à 15:10
Bonjour!
Je n'arrive pas à voir les données du champ "au_lname" et quand je clique sur le boutton "connect". Il y a ce message qui vient:
ExecuteReader requires an open and available Connection. The connection's current state is closed.
------------------------------------------------
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class ConnectionTester : System.Web.UI.Page
{
protected void cmdConnect_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = @"Data Source=localhost\SQLEXPRESS;" + "Initial Catalog=Master;Integrated Security=SSPI";
// Define the ADO.NET Connection object.
string connectiongString = WebConfigurationManager.ConnectionStrings["Master"].ConnectionString;
//SqlConnection myConnection = new SqlConnection(connectiongString);
try
{
using (myConnection)
{
// Try to open the connection.
myConnection.Open();
lblInfo.Text = " Server Version: " + myConnection.ServerVersion;
lblInfo.Text + = "
Connection Is:" + myConnection.State.ToString();
}
}
catch (Exception err)
{
// Handle an error by displaying the information.
lblInfo.Text = "Error reading the database.";
lblInfo.Text += err.Message;
}
lblInfo.Text += "
Now Connection Is: ";
lblInfo.Text + = myConnection.State.ToString();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "SELECT * FROM Authors ORDER BY au lname ";