Biaggio

I am developing a Windows Control for distribution via IE. The control accesses a database. In troubleshooting, I built the control with a button. The control comes up fine but when the button is clicked to access the database, I error on "Application attempted to perform an operation not allowed by security policy." I traced this to a strong name problem, but can't get the strong name to work in the control - it does work in a Windows application. So, taking the database access piece out of the equation, the full control code is as follows:

Imports System.Reflection

<Assembly: AssemblyKeyFileAttribute("C:\Share\sgkey.snk")>

Public Class UserControl1

Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

End Class

When the line that begins <Assembly... is commented out I can see the control in IE. When the line is left in, the control does not display.

I created the key file using the sn utility and located it as shown.

The control comes up fine when I drop it onto a Windows form but again, it does not display in IE (I get the icon for a missing object).

The HTML code that goes with the Control code above is:

<object classid="PlainControl.dll#PlainControl.UserControl1"

width="100%" height="100%" padding="0" margins="0">

</object>

The Control project is named Plain Control.

Lastly, I am bringing the control up directly from the Visual Studio environment. I mention that just in case it may be havinging an influence.

Thanks for any help,

Blaise



Re: ClickOnce and Setup & Deployment Projects Windows Control in IE, Problem Accessing Database, Strong Name doesn't seem to work

Wei Zhou - MSFT

Hi Biaggio

Why do you want to connect to database If you want to get data from server, you should use web service instead of connect to database. The following example shows how to do this.

Further more, you can delete strong name attribute.

Code Block

' -- Control

Partial Public Class IEUserControl

Inherits UserControl

Public Sub New()

InitializeComponent()

Dim btn As New Button()

btn.Text = "Test"

btn.Bounds = New Rectangle(0, 0, 100, 30)

AddHandler btn.Click, AddressOf btn_Click

Dim grid As New DataGridView()

grid.Bounds = New Rectangle(0, 40, 200, 200)

Me.BackColor = Color.Green

Me.Controls.Add(btn)

Me.Controls.Add(grid)

End Sub

Private Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)

Try

Using svc As New ForumWebService()

Dim ds As DataSet = svc.GetAllCustomers()

Dim grid As DataGridView = DirectCast(Me.Controls(1), DataGridView)

grid.DataMember = "Table"

grid.DataSource = ds

End Using

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

End Class

' -- Web Service

<WebService([Namespace]:="http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

Public Class ForumWebService

Inherits System.Web.Services.WebService

<WebMethod()> _

Public Function GetAllCustomers() As DataSet

Using conn As New SqlConnection("Data Source=.\;Initial Catalog=Test;Integrated Security=True")

Using cmd As New SqlCommand("SELECT * FROM Customer", conn)

Using adp As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

adp.Fill(ds)

Return ds

End Using

End Using

End Using

End Function

End Class

' -- HTML

<object id="IEControl" classid="CSWindowsControlLibrary.dll#CSWindowsControlLibrary.IEUserControl"

height="300" width="300" viewastext />

Best Regards,

Wei Zhou






Re: ClickOnce and Setup & Deployment Projects Windows Control in IE, Problem Accessing Database, Strong Name doesn't seem to work

Biaggio

Thanks for the attempt to help Wei. Indeed, one way, among many others, of getting data from a database is via a web service.

However, my very specific question is around connecting to a database from an IE hosted Windows Control. As to your question of "why" the Windows Control approach, that's a long, detailed discussion of my client's specific needs, and a proprietary one at that.