Security Exception Using DSN Connection

Results 1 to 2 of 2

Thread: Security Exception Using DSN Connection

  1. #1
    Join Date
    Dec 1969

    Default Security Exception Using DSN Connection

    I wrote an page, and have an access database. I was told by my web hoster that i need to use create a DSN connection, and give write rights to the database, all of which i did. however when i try to write to the database, i get the following error<BR><BR>System.Security.SecurityException: Request failed<BR><BR>the stack trace is <BR><BR>[SecurityException: Request failed.]<BR> ASP.What_aspx.InsertReviewAccess(String initials, String Opinion) +0<BR> ASP.What_aspx.Button1_Click(Object sender, EventArgs e) +74<BR> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108<BR> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57<BR> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18<BR> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33<BR> System.Web.UI.Page.ProcessRequestMain() +2106<BR> System.Web.UI.Page.ProcessRequest() +218<BR> System.Web.UI.Page.ProcessRequest(HttpContext context) +18<BR> System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication+IExecutionStep.Execute() +179<BR> System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +87<BR><BR>My code to connect to the Database is<BR><BR> Function InsertReviewAccess(Byval initials as string, ByVal Opinion as string) As Integer<BR><BR> &#039;Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source= ../db/AccessforWebMatrix.mdb"<BR> &#039;Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )<BR><BR> dim DSN, OBJdbConnection<BR> DSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../db/AccessforWebMatrix.mdb") & ";"<BR> OBJdbConnection = Server.CreateObject("ADODB.Connection")<BR> OBJdbConnection.Open(DSN)<BR><BR> Dim queryString As String = "INSERT INTO [WhatPPLAreSaying] ([Initials], [Opinion]) VALUES (@initials, @opinion)"<BR> Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand<BR> dbCommand.CommandText = queryString<BR> dbCommand.Connection = OBJdbConnection<BR><BR><BR> Dim dbParam_initials As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter<BR> dbParam_initials.ParameterName = "@initials"<BR> dbParam_initials.Value = initials<BR> dbParam_initials.DbType = System.Data.DbType.String<BR> dbCommand.Parameters.Add(dbParam_initials)<BR><BR> <BR> Dim dbParam_opinion As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter<BR> dbParam_opinion.ParameterName = "@opinion"<BR> dbParam_opinion.Value = opinion<BR> dbParam_opinion.DbType = System.Data.DbType.String<BR> dbCommand.Parameters.Add(dbParam_opinion)<BR><BR> Dim rowsAffected As Integer = 0<BR> OBJdbConnection.Open<BR> Try<BR> rowsAffected = dbCommand.ExecuteNonQuery<BR> Finally<BR> OBJdbConnection.Close<BR> End Try<BR><BR> Return rowsAffected<BR> End Function<BR><BR><BR>before i created the DSN connection, it worked fine. The webhoster said that i had a scripting error.<BR><BR>the page can be viewed at ""<BR><BR>any hellp would be great, thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Security Exception Using DSN Connection

    Why were you using the IDbConnection,IDbCommand Interface instead of OleDb objects when connecting using OldDb provider?<BR><BR>In you code you are stuffing the ADO.NET command&#039;s connection property with an ADO Connection, which only guarantees failure.<BR><BR>To use a DSN, you need to connect using ODBC.NET Data Provider<BR><BR>Dim DSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../db/AccessforWebMatrix.mdb") & ";"<BR>Dim conn As OdbcConnection = New OdbcConnection(DSN)<BR>conn.Open()<BR><BR>Dim dbCommand As New OdbcCommand()<BR>dbCommand.CommandText = queryString<BR>dbCommand.Connection = conn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts