Error en Webpart propio

08/07/2004 - 17:30 por Leticia Martín | Informe spam
Hola, he conseguido crear diferentes web parts. Pero
cuando intento crear un webpart que accede a una base de
datos y muestro los datos en un DataGrid no llega a
importarlo (consigo cargarlo pero al arrastralo)se me va
a :

"http://asweb03:82/_layouts/3082/error.aspx?
ErrorID=SpecificWebPartError&ErrorIDArgs=WebPart1&ErrorLink
TextID=MaintenancePageLinkText&ErrorLinkDescriptionID=Maint
enancePageDescription&ErrorLinkNavigateUrl=spcontnt%2Easpx%
3FPageView%3DShared%26url%3D%252fdefault%2Easpx%253fMode%
253dEdit%2526PageView%253dShared"

y aparece lo siguiente:

Error:

El elemento Web "WebPart1" parece estar causando un
problema.

Página de mantenimiento de elementos Web: Si tiene
permiso, puede usar esta página para deshabilitar
temporalmente elementos Web o quitar la configuración
personal. Para obtener más información, póngase en
contacto con el administrador del sitio.


Solucionar problemas de Windows SharePoint Services.

Os pongo el código del Webpart:


sing System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
using System.Web.UI.HtmlControls;using System.Data;
using System.Data.SqlClient;
namespace Ultimo
{
/// <summary>
/// Description for WebPart1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebPart1 runat=server></
{0}:WebPart1>"),
XmlRoot(Namespace="Ultimo")]
public class WebPart1 :
Microsoft.SharePoint.WebPartPages.WebPart
{


DataGrid MyDataGrid = new DataGrid();

protected override void
CreateChildControls (){
SqlConnection myConnection = new
SqlConnection("server=(local)
\\NetSDK;database=pubs;Integrated Security=SSPI");
myConnection.Open();
SqlDataAdapter myCommand = new
SqlDataAdapter("select au_id from Authors where au_lname
like '%Whi%'", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");





this.Controls.Add(MyDataGrid );


MyDataGrid.DataSource=ds.Tables
["Authors"].DefaultView;
MyDataGrid.DataBind();
myConnection.Close();
}
protected override void RenderWebPart
(HtmlTextWriter output)
{
EnsureChildControls();
output.RenderBeginTag
("table");

output.RenderBeginTag("tr"); //Add
a row
output.RenderBeginTag("td"); //
Add a cell

//Render DataGrid
MyDataGrid.RenderControl
(output);
output.RenderEndTag(); //End of
the cell tag
output.RenderEndTag(); //End of
the row tag

output.RenderBeginTag("tr"); //Add
a row
output.AddStyleAttribute(

HtmlTextWriterStyle.Height, "5");
output.RenderBeginTag("td"); //
Add a cell
output.RenderEndTag(); //End of
the cell tag
output.RenderEndTag(); //End of
the row tag

output.RenderBeginTag("tr"); //Add
a row
output.AddStyleAttribute(

HtmlTextWriterStyle.FontWeight,
"bold");
output.RenderBeginTag("td"); //
Add a cell
output.Write("Selected Customer
Details");
output.RenderEndTag(); //End of
the cell tag
output.RenderEndTag(); //End of
the row tag

}


}
}


Gracias.
Por favor si alguien sabe algo??
Leticia.
Pd: si este código lo meto en un aspx, funciona.
 

Leer las respuestas

#1 CESAR DE LA TORRE [Microsoft MVP]
08/07/2004 - 21:33 | Informe spam
Si haces un Debugging del WebPart te saldrá el error.
Para hacer un Debugging de un WebPart tienes que hacer un attach to process
desde VS.NET-->debugging-->Procesos al Worker Proces de Apication Pool de
IIS que esté utilizando tu WebSite de IIS. El proceso será uno de los
w3wp.exe que aparezcan en la lista de procesos.

Si simplemente quieres que te salga el error en IE en la ejecución del
WebPart, cambia en el Web.config de SharePoint 2003 y especifica
CustomErrors a 'off' y además la opción de 'CallStack' a 'true'. Con eso te
saldrán los errores en lugar del custom error de "Página de mantenimiento de
elementos Web".

En cuanto a qué puede ser tu error... Así sin probarlo y habiendole echado
un vistazo a tu código, podría ser un problema de seguridad. Estás
especificando un string de conexión con seguridad integrada. Asegurate de
que has habilitado impersonación en el Web.config del site de SharePoint
2003, se hace habilitando la opción 'impersonation' a 'true'. (Si no haces
esto, no intenta conectarse con el usuario que está autenticado con IE).
Otra opción para probar si es esto es que uses un string de conexión a SQL
Server con usuario y password de un usuario interno de SQL Server en lugar
de utilizar seguridad integrada.

En cualquier caso, lo mas importante es que consigas ver el error, bien
haciendo Debugging o bien con las opciones de ver los errores que te decía
arriba.

César de la Torre
[Microsoft MVP - XML WebServices]
[MCSE] [MCT]

Renacimiento
Microsoft GOLD Certified Partner
www.renacimiento.com



"Leticia Martín" wrote in message
news:290c101c46500$70a6ee10$
Hola, he conseguido crear diferentes web parts. Pero
cuando intento crear un webpart que accede a una base de
datos y muestro los datos en un DataGrid no llega a
importarlo (consigo cargarlo pero al arrastralo)se me va
a :

"http://asweb03:82/_layouts/3082/error.aspx?
ErrorID=SpecificWebPartError&ErrorIDArgs=WebPart1&ErrorLink
TextID=MaintenancePageLinkText&ErrorLinkDescriptionID=Maint
enancePageDescription&ErrorLinkNavigateUrl=spcontnt%2Easpx%
3FPageView%3DShared%26url%3D%252fdefault%2Easpx%253fMode%
253dEdit%2526PageView%253dShared"

y aparece lo siguiente:

Error:

El elemento Web "WebPart1" parece estar causando un
problema.

Página de mantenimiento de elementos Web: Si tiene
permiso, puede usar esta página para deshabilitar
temporalmente elementos Web o quitar la configuración
personal. Para obtener más información, póngase en
contacto con el administrador del sitio.


Solucionar problemas de Windows SharePoint Services.

Os pongo el código del Webpart:


sing System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
using System.Web.UI.HtmlControls;using System.Data;
using System.Data.SqlClient;
namespace Ultimo
{
/// <summary>
/// Description for WebPart1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebPart1 runat=server></
{0}:WebPart1>"),
XmlRoot(Namespace="Ultimo")]
public class WebPart1 :
Microsoft.SharePoint.WebPartPages.WebPart
{


DataGrid MyDataGrid = new DataGrid();

protected override void
CreateChildControls (){
SqlConnection myConnection = new
SqlConnection("server=(local)
\\NetSDK;database=pubs;Integrated Security=SSPI");
myConnection.Open();
SqlDataAdapter myCommand = new
SqlDataAdapter("select au_id from Authors where au_lname
like '%Whi%'", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");





this.Controls.Add(MyDataGrid );


MyDataGrid.DataSource=ds.Tables
["Authors"].DefaultView;
MyDataGrid.DataBind();
myConnection.Close();
}
protected override void RenderWebPart
(HtmlTextWriter output)
{
EnsureChildControls();
output.RenderBeginTag
("table");

output.RenderBeginTag("tr"); //Add
a row
output.RenderBeginTag("td"); //
Add a cell

//Render DataGrid
MyDataGrid.RenderControl
(output);
output.RenderEndTag(); //End of
the cell tag
output.RenderEndTag(); //End of
the row tag

output.RenderBeginTag("tr"); //Add
a row
output.AddStyleAttribute(

HtmlTextWriterStyle.Height, "5");
output.RenderBeginTag("td"); //
Add a cell
output.RenderEndTag(); //End of
the cell tag
output.RenderEndTag(); //End of
the row tag

output.RenderBeginTag("tr"); //Add
a row
output.AddStyleAttribute(

HtmlTextWriterStyle.FontWeight,
"bold");
output.RenderBeginTag("td"); //
Add a cell
output.Write("Selected Customer
Details");
output.RenderEndTag(); //End of
the cell tag
output.RenderEndTag(); //End of
the row tag

}


}
}


Gracias.
Por favor si alguien sabe algo??
Leticia.
Pd: si este código lo meto en un aspx, funciona.

Preguntas similares