Quando mando in esecuzione questo codice:
Databinder.aspx.cs
Databinder.aspxcodice: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.Sql; using System.Data.SqlClient; using System.Data.SqlTypes; public partial class DataBinder : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); builder.DataSource = "localhost\\SQLExpress"; builder.IntegratedSecurity = true; builder.InitialCatalog = "Daniele"; using(SqlConnection conn = new SqlConnection(builder.ConnectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("SELECT * FROM Products WHERE Cognome='Rossi'", conn)) { SqlDataReader query = cmd.ExecuteReader(); SqlDataSource sorgente = new SqlDataSource(); sorgente.ID = "connessione"; Page.Controls.Add(sorgente); sorgente.ConnectionString = builder.ConnectionString; sorgente.SelectCommand = query.ToString(); GridView1.DataSource = sorgente; GridView1.DataBind(); } } } }
mi viene fuori questo errore:codice:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataBinder.aspx.cs" Inherits="DataBinder" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </div> </form> </body> </html>
Errore server nell'applicazione '/'.
Impossibile trovare il server 'System' in sys.servers. Verificare che sia stato specificato il nome corretto del server. Se necessario, eseguire la stored procedure sp_addlinkedserver per aggiungere il server a sys.servers.
Descrizione: Eccezione non gestita durante l'esecuzione della richiesta Web corrente. Per ulteriori informazioni sull'errore e sul suo punto di origine nel codice, vedere la traccia dello stack.
Dettagli eccezione: System.Data.SqlClient.SqlException: Impossibile trovare il server 'System' in sys.servers. Verificare che sia stato specificato il nome corretto del server. Se necessario, eseguire la stored procedure sp_addlinkedserver per aggiungere il server a sys.servers.
La linea di codice incriminata che mi segnala il debugger è:
Cosa sbaglio???codice:GridView1.DataBind()

Rispondi quotando