Showing posts with label access. Show all posts
Showing posts with label access. Show all posts

Thursday, March 29, 2012

Office interop from asp.net (vb) - permissions problem....

Hi,

I am trying to open a word document from an asp.net page but I keep getting
an access denied error when I try to create an instance of the word
applications.

I have created references to the Office 11.0 Object and it imported the
other references (except stdole which I did manually)

I have imported namepsaces:

Imports System.ComponentModel
Imports Microsoft.Office.Interop

The code I am calling is:

Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
oWordApp = New Word.Application '<<<<<<<<<<<<<<<<< ERROR
oWordDoc = oWordApp.Documents.Open("c:\text.doc")

The error below says I should give access permission to the ASPNET user. But
a) that user does not exist on my machine - I think it is 'Authenticated
user' that I need and b) which file needs to be given permission?!? I have
tried giving this user full control over the entire Office folder (not
something I'd do on a production server), but no go!

Does anyone know which file needs permission? Any other suggestions?

Thanks in advance,

Stuart

================================================== ==================
The error:
Access is denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or
Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user (typically
IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer,
choose "Properties" and select the Security tab. Click "Add" to add the
appropriate user or group. Highlight the ASP.NET account, and check the
boxes for the desired access.No. ASPNET is a restricted account that's somewhat like "guest" account. It
cannot be used to execute anything outside your web process.

Instead, you should try to "impersonate"(Google for this keyword for usage)
a real "user" account, and give the "user" permission to that directory too,
of course.

"Stu" <s.lock@.cergis.com> glsD:OTqqejQjFHA.3144@.TK2MSFTNGP12.phx.g bl...
> Hi,
> I am trying to open a word document from an asp.net page but I keep
> getting an access denied error when I try to create an instance of the
> word applications.
> I have created references to the Office 11.0 Object and it imported the
> other references (except stdole which I did manually)
> I have imported namepsaces:
> Imports System.ComponentModel
> Imports Microsoft.Office.Interop
> The code I am calling is:
> Dim oWordApp As Word.Application
> Dim oWordDoc As Word.Document
> oWordApp = New Word.Application '<<<<<<<<<<<<<<<<< ERROR
> oWordDoc = oWordApp.Documents.Open("c:\text.doc")
> The error below says I should give access permission to the ASPNET user.
> But a) that user does not exist on my machine - I think it is
> 'Authenticated user' that I need and b) which file needs to be given
> permission?!? I have tried giving this user full control over the entire
> Office folder (not something I'd do on a production server), but no go!
> Does anyone know which file needs permission? Any other suggestions?
> Thanks in advance,
> Stuart
>
> ================================================== ==================
> The error:
> Access is denied.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.UnauthorizedAccessException: Access is denied.
> ASP.NET is not authorized to access the requested resource. Consider
> granting access rights to the resource to the ASP.NET request identity.
> ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5
> or Network Service on IIS 6) that is used if the application is not
> impersonating. If the application is impersonating via <identity
> impersonate="true"/>, the identity will be the anonymous user (typically
> IUSR_MACHINENAME) or the authenticated request user.
> To grant ASP.NET write access to a file, right-click the file in Explorer,
> choose "Properties" and select the Security tab. Click "Add" to add the
> appropriate user or group. Highlight the ASP.NET account, and check the
> boxes for the desired access.
Many thanks - that did the trick.

Stu

"Lau Lei Cheong" <leu_lc@.yehoo.com.hk> wrote in message
news:evrIHLRjFHA.3580@.TK2MSFTNGP09.phx.gbl...
> No. ASPNET is a restricted account that's somewhat like "guest" account.
> It cannot be used to execute anything outside your web process.
> Instead, you should try to "impersonate"(Google for this keyword for
> usage) a real "user" account, and give the "user" permission to that
> directory too, of course.
> "Stu" <s.lock@.cergis.com>
> glsD:OTqqejQjFHA.3144@.TK2MSFTNGP12.phx.g bl...
>> Hi,
>>
>> I am trying to open a word document from an asp.net page but I keep
>> getting an access denied error when I try to create an instance of the
>> word applications.
>>
>> I have created references to the Office 11.0 Object and it imported the
>> other references (except stdole which I did manually)
>>
>> I have imported namepsaces:
>>
>> Imports System.ComponentModel
>> Imports Microsoft.Office.Interop
>>
>> The code I am calling is:
>>
>> Dim oWordApp As Word.Application
>> Dim oWordDoc As Word.Document
>> oWordApp = New Word.Application '<<<<<<<<<<<<<<<<< ERROR
>> oWordDoc = oWordApp.Documents.Open("c:\text.doc")
>>
>> The error below says I should give access permission to the ASPNET user.
>> But a) that user does not exist on my machine - I think it is
>> 'Authenticated user' that I need and b) which file needs to be given
>> permission?!? I have tried giving this user full control over the entire
>> Office folder (not something I'd do on a production server), but no go!
>>
>> Does anyone know which file needs permission? Any other suggestions?
>>
>> Thanks in advance,
>>
>> Stuart
>>
>>
>> ================================================== ==================
>> The error:
>> Access is denied.
>> Description: An unhandled exception occurred during the execution of the
>> current web request. Please review the stack trace for more information
>> about the error and where it originated in the code.
>>
>> Exception Details: System.UnauthorizedAccessException: Access is denied.
>>
>> ASP.NET is not authorized to access the requested resource. Consider
>> granting access rights to the resource to the ASP.NET request identity.
>> ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5
>> or Network Service on IIS 6) that is used if the application is not
>> impersonating. If the application is impersonating via <identity
>> impersonate="true"/>, the identity will be the anonymous user (typically
>> IUSR_MACHINENAME) or the authenticated request user.
>>
>> To grant ASP.NET write access to a file, right-click the file in
>> Explorer, choose "Properties" and select the Security tab. Click "Add" to
>> add the appropriate user or group. Highlight the ASP.NET account, and
>> check the boxes for the desired access.
>>
Many thanks - that did the trick.

Stu

"Lau Lei Cheong" <leu_lc@.yehoo.com.hk> wrote in message
news:evrIHLRjFHA.3580@.TK2MSFTNGP09.phx.gbl...
> No. ASPNET is a restricted account that's somewhat like "guest" account.
> It cannot be used to execute anything outside your web process.
> Instead, you should try to "impersonate"(Google for this keyword for
> usage) a real "user" account, and give the "user" permission to that
> directory too, of course.
> "Stu" <s.lock@.cergis.com>
> glsD:OTqqejQjFHA.3144@.TK2MSFTNGP12.phx.g bl...
>> Hi,
>>
>> I am trying to open a word document from an asp.net page but I keep
>> getting an access denied error when I try to create an instance of the
>> word applications.
>>
>> I have created references to the Office 11.0 Object and it imported the
>> other references (except stdole which I did manually)
>>
>> I have imported namepsaces:
>>
>> Imports System.ComponentModel
>> Imports Microsoft.Office.Interop
>>
>> The code I am calling is:
>>
>> Dim oWordApp As Word.Application
>> Dim oWordDoc As Word.Document
>> oWordApp = New Word.Application '<<<<<<<<<<<<<<<<< ERROR
>> oWordDoc = oWordApp.Documents.Open("c:\text.doc")
>>
>> The error below says I should give access permission to the ASPNET user.
>> But a) that user does not exist on my machine - I think it is
>> 'Authenticated user' that I need and b) which file needs to be given
>> permission?!? I have tried giving this user full control over the entire
>> Office folder (not something I'd do on a production server), but no go!
>>
>> Does anyone know which file needs permission? Any other suggestions?
>>
>> Thanks in advance,
>>
>> Stuart
>>
>>
>> ================================================== ==================
>> The error:
>> Access is denied.
>> Description: An unhandled exception occurred during the execution of the
>> current web request. Please review the stack trace for more information
>> about the error and where it originated in the code.
>>
>> Exception Details: System.UnauthorizedAccessException: Access is denied.
>>
>> ASP.NET is not authorized to access the requested resource. Consider
>> granting access rights to the resource to the ASP.NET request identity.
>> ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5
>> or Network Service on IIS 6) that is used if the application is not
>> impersonating. If the application is impersonating via <identity
>> impersonate="true"/>, the identity will be the anonymous user (typically
>> IUSR_MACHINENAME) or the authenticated request user.
>>
>> To grant ASP.NET write access to a file, right-click the file in
>> Explorer, choose "Properties" and select the Security tab. Click "Add" to
>> add the appropriate user or group. Highlight the ASP.NET account, and
>> check the boxes for the desired access.
>>

Office Web Componenets for Access?

Has anyone had success with Office Web Components with Access? What I have
in mind is a site where Access users can log in and update their Access
databases with new records that have been uploaded by other Access users.
Or perhaps I could have a "shared records" page where anyone can update/add
to a shared record.

The purpose is to have a "sometimes connected" Access application where
folks can log on and share/update/synchronize records as they have
opportunity.

Has anyone done this? Is this even possible with OWC?

Thanks in advance.yup, its possible. The OWC components can handle user input quiet easily
with little work on your part. There are licensing issues you have to
contend with but you can read more about the intricacies of licensing in the
black book.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @. www.lulu.com/owc, Amazon.com etc
"deko" <deko@.deko.com> wrote in message
news:%B0ve.1889$N22.1854@.newssvr21.news.prodigy.co m...
> Has anyone had success with Office Web Components with Access? What I
> have
> in mind is a site where Access users can log in and update their Access
> databases with new records that have been uploaded by other Access users.
> Or perhaps I could have a "shared records" page where anyone can
> update/add
> to a shared record.
> The purpose is to have a "sometimes connected" Access application where
> folks can log on and share/update/synchronize records as they have
> opportunity.
> Has anyone done this? Is this even possible with OWC?
> Thanks in advance.

Saturday, March 24, 2012

OLAP and ASP.NET

I am working on Analysis Services. We are developing an
ASP.NET application which will access data from OLAP
Cubes. creation of OLAP Cube is done.

I am not able to access the same from asp.net. Can someone
please help me ? How do i access OLAP Cube in ASP.NET
applcation??

are there any custom controls or code examples plz help
urgent...these is no direct mdx support in .net. you have to use the OleDbReader
(with lastest sp), or create interop wrappers for the mdx com objects

-- bruce (sqlwork.com)

"Melroy" <melroy_britto@.hotmail.com> wrote in message
news:2cc2401c39400$86e8a410$a601280a@.phx.gbl...
> I am working on Analysis Services. We are developing an
> ASP.NET application which will access data from OLAP
> Cubes. creation of OLAP Cube is done.
> I am not able to access the same from asp.net. Can someone
> please help me ? How do i access OLAP Cube in ASP.NET
> applcation??
> are there any custom controls or code examples plz help
> urgent...

OLE DB Connections

When I try to connect to a MS Access database an exception occurs that tells me that "the datafile is either already opened exclusive by another user or you don'y have permission to access the data". This occurs on my computer - I'm developing an application in Visual Studio.net- not on a remote server. The file in question has been set to shared access and is not open at the time the connection attempt is made. Any suggestions?where is your database?if it's under intepub folder then change it's location like c:\mydatabase\yourfile.mdb .It will solve your problem
Arvind
Hi,

does the aspnet_user account on your machine have write permissions on the folder where your access database resides?

Grz, Kris.
I've tried both suggestions and still no luck. I've also tried to connect with the Nothwinds database example by placing it in a variety of directories and I can't connect to it either. This is what I get:

Server Error in '/DBid' Application.
------------------------

The Microsoft Jet database engine cannot open the file 'C:\dbidmaster.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: The Microsoft Jet database engine cannot open the file 'C:\dbidmaster.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

Source Error:

Line 128: Dim dr As OleDb.OleDbDataReader
Line 129:
Line 130: OleDbConnection1.Open()
Line 131: dr = OleDbCommand1.ExecuteReader
Line 132:

Source File: c:\inetpub\wwwroot\DBid\Login.aspx.vb Line: 130

Stack Trace:

[OleDbException (0x80004005): The Microsoft Jet database engine cannot open the file 'C:\dbidmaster.mdb'. It is already opened exclusively by another user, or you need permission to view its data.]
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) +20
System.Data.OleDb.OleDbConnection.InitializeProvider() +57
System.Data.OleDb.OleDbConnection.Open() +203
DBid.Login.btnSubmit_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\DBid\Login.aspx.vb:130
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292

------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032
I think your *.mdb file was opened by the Microsoft Office Access
or, in your code you may not close the DataReader or the Connections last time

Ole object

I want to display pictures from access database in repeater but instead i receive some
windows with red crosses.
It should be a good solution but it dont work.
This is my .aspx code (well its not main i copied it from another site for my learnigs):

<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %><script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mappath("/photolib.mdb"))

dbconn.Open()
sql="SELECT smallimage FROM photo"
--smallimage is an OLE object column connected with .jpg files in my database
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
photo.DataSource=dbread
photo.DataBind()
dbread.Close()
dbconn.Close()
end sub
</script
<form runat="server">
<asp:Repeater id="photo" runat="server"><HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Small Image</th>
</tr>
</HeaderTemplate><ItemTemplate>
<tr>
<td><img src="http://pics.10026.com/?src=<%#Container.DataItem("smallimage")%>"></td
</tr>
</ItemTemplate><FooterTemplate>
</table>
</FooterTemplate></asp:Repeater>
</form
Thanks for any tips or ideas you can give me.The img src attribute should be specified with a location of the file, not the file data itself. One possible way is to have the pictures stored as files on the webserver, and have the field smallimage of the database table points to the corresponding picture file as a relative url. Then when loading the page, the web browser would be able to request the picture file according to the url specified to the src attribute of img tag.
Hi,

In the src of your image, you're supposed to put the URL where the browser will find the picture. Here, you're giving it the image itself. The browser fails to see a valid url there, and displays a red cross.
What you want to do is build a HttpHandler that will get some photo id as a url parameter. in the img src, put the address of the handler (something like blah.ashx?photoid=25).
The handler will send the contents of the image field of your database directly to the response binary stream and set the content type.
Checkthis for a tutorial (even though they should use a HttpHandler instead of an aspx page).

Let me know if this helps.

(BTW, there's a strange header thing in OLE fields in Access which may force you to skip the first 16 or something bytes of the field)
Thanks.
But i already have my .jpg files stored on my webserver, besides i have this files connected to smallimage column in database (access 2000 allows to make .jpg files elemet of database file and that is exactly what i have done).Shouldn't .aspx file read picture data directly from database in this case.
Thanks.
Yes, putting direct source to all .jpg files would propably solve the thing.But i have made .jpg files elemet of database file.Shouldn't .aspx file read picture data directly from database in this case.The other solution (httphandler) lies so far beyond my knowledge(I'm rather a begginer in asp.net).
Sorry. First reply is to Frank Tse and second to bleroy.
In your example the databind expression
<%#Container.DataItem("smallimage")%
does read the picture data from database and included in the response. However, the usage of the src attribute in img tag is expecting a URL to be specified, not the picture data itself (accroding to html spec).

So if you already have the pictures files on the server, all you need to bind the value to the src attribute is the location of the picture files. Otherwise, if the picture data must be retrieved from the database directly, you would need bleroy's HttpHandler approach.
My Access 2000 was the problem it didn't connect database ole object with .jpg file.I don't know why.I have convert my database to sql database.I have set my picture field as varchar.I set source of my pictures like that:
<img src="http://pics.10026.com/?src=image source"/<%# DataBinder.Eval
(Container.DataItem, "Column name") %>'

And now it works perfectly.
Anyway thanks for help.

OLE version of microsoft applicaton block data access?

I used microsoft data access application block a lot. It make data access
task much easier.
However, it is only available for SQL client, does anyone has a OLE version?
?
regards,
Guoqi Zheng
http://www.ureader.com"guoqi zheng"<no@.sorry.com> wrote in
news:2adae36c2f8347868b22947a97cdf6e7@.ur
eader.com:

> I used microsoft data access application block a lot. It make data
> access task much easier.
> However, it is only available for SQL client, does anyone has a OLE
> version'
Nope, no OLE version. V3.0 does support Microsoft SQL Server, Oracle, and
DB2 however.
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]
"guoqi zheng" <no@.sorry.com> wrote in message
news:2adae36c2f8347868b22947a97cdf6e7@.ur
eader.com...

>I used microsoft data access application block a lot. It make data access
> task much easier.
> However, it is only available for SQL client, does anyone has a OLE
> version'
As you say, the current version supports SQLClient only, but it would not be
a major undertaking to create a version of it for OleDb as the object
interfaces are to all intents and purposes the same.

OLE version of microsoft applicaton block data access?

I used microsoft data access application block a lot. It make data access
task much easier.

However, it is only available for SQL client, does anyone has a OLE version??

regards,

Guoqi Zheng
http://www.ureader.com"guoqi zheng"<no@.sorry.com> wrote in
news:2adae36c2f8347868b22947a97cdf6e7@.ureader.com:

> I used microsoft data access application block a lot. It make data
> access task much easier.
> However, it is only available for SQL client, does anyone has a OLE
> version??

Nope, no OLE version. V3.0 does support Microsoft SQL Server, Oracle, and
DB2 however.

--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
"guoqi zheng" <no@.sorry.com> wrote in message
news:2adae36c2f8347868b22947a97cdf6e7@.ureader.com. ..

>I used microsoft data access application block a lot. It make data access
> task much easier.
> However, it is only available for SQL client, does anyone has a OLE
> version??

As you say, the current version supports SQLClient only, but it would not be
a major undertaking to create a version of it for OleDb as the object
interfaces are to all intents and purposes the same.

OleDb

Hi,
I've been using SQL objects in .NET ever since I started, so I'm alittle loss now when it comes to OleDb, how to get data in and out ofMS Access. Are there any links or quickstarts I could read through?
Try this:
http://www.dotnetspider.com/technology/tutorials/CRUDSample.aspx
Thanks, that was helpful.

OLEDB Access Path[solved]

i have an aspx page in which i want to connect access (mdb) database using OLEDB but in data source property what path i have to give. my aspx and mdb database is in same dir. when i gave it simple "dbname.mdb" it goes to C:\windows\system\
please tell mepost the connectionstring you are using to connect to the database.
Solved

i was just missing Server.Mappath Object

Thursday, March 22, 2012

OleDb FoxPro Problems!

Hi,

I was using the code below to pull up records from an access database which worked fine, but I now want to do the same to a foxpro 7 database.

It connects to the foxpro dbase but after stepping through the code I found it crashes at

"dgPrevious.DataSource = cmdSelect.ExecuteReader"

the error is "Object reference not set to an instance of an object."

Dim con As OleDb.OleDbConnection
Dim cmdSelect As OleDb.OleDbCommand

Call OpenConnection() ' Own procedure

sqlquery = "SELECT Datereq, NetLogin, Title, Status, RequestId FROM " & tbname

cmdSelect = New OleDb.OleDbCommand(sqlquery, con)

dgPrevious.DataSource = cmdSelect.ExecuteReader

dgPrevious.DataBind()

Thanks

ChrisBy experience I find that if there is a problem with db connection it fails after code for connection but when you apply it.
Can you post the code for Call OpenConnection() ?
I suspect there is a problem here (perhaps).

OLEDB Provider for SQL SERVER + Parameterized Queries

Hi,

I currently have an application that connects to an MS ACCESS database. This
application uses an OLEDB connection string for MS ACCESS.
Now, I'd like to upsize the application so I converted the db to SQL SERVER
and this went well.

Next thing I changed the connection string from OLEDB for MS ACCESS to OLEDB
for SQL SERVER.
I expected this to work resonably well, however I found that it never worked
at all.
The reason is that I have done all my MS ACCESS queries using dynamic SQL
and Parameterized queries like so

objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM tblSecurity WHERE
UserName=@dotnet.itags.org.UserName AND Secretword=@dotnet.itags.org.Password"
This seems to work fine for access, But the OLEDB provider for SQL SERVER
complains bitterly about this, for example, attempting to execurte the above
query with attached parameters gives me the following error

Must declare the variable '@dotnet.itags.org.UserName'.

Can anybody please explain why these two database will not work with the
same syntax even though I am using an OLEDB connection string / Provider for
both.

I have included my full code below.
Please note that this works with an MS ACCESS OLEDB connection string but
NOT an OLEDB SQL SERVER CONNECTION STRING.

many thanks in advance.

cheers

martin.
================================================== ================================================== =====

Dim objConn As System.Data.OleDb.OleDbConnection = New
System.Data.OleDb.OleDbConnection()
Dim objCMD As System.Data.OleDb.OleDbCommand = New
System.Data.OleDb.OleDbCommand()
Try
'Trace.Warn("Con string", OleDbConnection1.ConnectionString)
objConn.ConnectionString() = Application("ConnectionString")
objCMD.Connection = objConn
objConn.Open()
Trace.Warn("Con string", objConn.ConnectionString())
objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM
tblSecurity WHERE UserName=@dotnet.itags.org.UserName AND Secretword=@dotnet.itags.org.Password"
Trace.Warn("Database", "database open")
Dim Param1 As System.Data.OleDb.OleDbParameter
Dim Param2 As System.Data.OleDb.OleDbParameter
Param1 = objCMD.Parameters.Add("@dotnet.itags.org.UserName",
TextBox1.Text.Trim())
Param2 = objCMD.Parameters.Add("@dotnet.itags.org.Password",
Password1.Value.Trim())
intNumUsers = objCMD.ExecuteScalar() 'Execute the query
'ERROR THROWN HERE WORKS ON ACCESS BUT NOT SS
Trace.Warn("Database", "No database error occured")
Catch err As Exception
Dim strErrMessage As String
strErrMessage = "Exception thrown function btnLogin_Click" &
Request.ServerVariables("SCRIPT_NAME") & "<br>"
Trace.Write("ERROR", err.Message.ToString)
'Response.End()
'EmailException(err.Message, strErrMessage)
Finally
If objConn.State = ConnectionState.Open Then
Try
'Attempt to close the connection
objConn.Close()
Catch err As Exception
'Catch any error that may occur
Dim strErrMessage As String
strErrMessage = "Exception thrown attemping to close
after checking the user is in admin. File " &
Request.ServerVariables("SCRIPT_NAME") & "<br>"
EmailException(err.Message, strErrMessage)
End Try
End If
End TryI think as part of your migration to SQL Server you should migrate your
dynamic sql code to stored procedures, I'm not sure that there is anything
you can do to make the code you have work the way it is. Having that said if
your going to have to change it you might as well use sp's.

"Martin" wrote:

> Hi,
> I currently have an application that connects to an MS ACCESS database. This
> application uses an OLEDB connection string for MS ACCESS.
> Now, I'd like to upsize the application so I converted the db to SQL SERVER
> and this went well.
> Next thing I changed the connection string from OLEDB for MS ACCESS to OLEDB
> for SQL SERVER.
> I expected this to work resonably well, however I found that it never worked
> at all.
> The reason is that I have done all my MS ACCESS queries using dynamic SQL
> and Parameterized queries like so
> objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM tblSecurity WHERE
> UserName=@.UserName AND Secretword=@.Password"
> This seems to work fine for access, But the OLEDB provider for SQL SERVER
> complains bitterly about this, for example, attempting to execurte the above
> query with attached parameters gives me the following error
> Must declare the variable '@.UserName'.
> Can anybody please explain why these two database will not work with the
> same syntax even though I am using an OLEDB connection string / Provider for
> both.
>
> I have included my full code below.
> Please note that this works with an MS ACCESS OLEDB connection string but
> NOT an OLEDB SQL SERVER CONNECTION STRING.
> many thanks in advance.
> cheers
> martin.
> ================================================== ================================================== =====
>
>
> Dim objConn As System.Data.OleDb.OleDbConnection = New
> System.Data.OleDb.OleDbConnection()
> Dim objCMD As System.Data.OleDb.OleDbCommand = New
> System.Data.OleDb.OleDbCommand()
> Try
> 'Trace.Warn("Con string", OleDbConnection1.ConnectionString)
> objConn.ConnectionString() = Application("ConnectionString")
> objCMD.Connection = objConn
> objConn.Open()
> Trace.Warn("Con string", objConn.ConnectionString())
> objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM
> tblSecurity WHERE UserName=@.UserName AND Secretword=@.Password"
> Trace.Warn("Database", "database open")
> Dim Param1 As System.Data.OleDb.OleDbParameter
> Dim Param2 As System.Data.OleDb.OleDbParameter
> Param1 = objCMD.Parameters.Add("@.UserName",
> TextBox1.Text.Trim())
> Param2 = objCMD.Parameters.Add("@.Password",
> Password1.Value.Trim())
> intNumUsers = objCMD.ExecuteScalar() 'Execute the query
> 'ERROR THROWN HERE WORKS ON ACCESS BUT NOT SS
> Trace.Warn("Database", "No database error occured")
> Catch err As Exception
> Dim strErrMessage As String
> strErrMessage = "Exception thrown function btnLogin_Click" &
> Request.ServerVariables("SCRIPT_NAME") & "<br>"
> Trace.Write("ERROR", err.Message.ToString)
> 'Response.End()
> 'EmailException(err.Message, strErrMessage)
> Finally
> If objConn.State = ConnectionState.Open Then
> Try
> 'Attempt to close the connection
> objConn.Close()
> Catch err As Exception
> 'Catch any error that may occur
> Dim strErrMessage As String
> strErrMessage = "Exception thrown attemping to close
> after checking the user is in admin. File " &
> Request.ServerVariables("SCRIPT_NAME") & "<br>"
> EmailException(err.Message, strErrMessage)
> End Try
> End If
> End Try
>
>
I agree entirely, you are totally right - If you use SQL SERVER the sp's are
definatly the way to go.
However I would be interested to find out why parameterised queries work
with the OLEDB provider for MS ACCESS but NOT with the OLEDB provider for
SQL SERVER.

"Alien2_51" <dan.billow.remove@.monacocoach.removeme.com> wrote in message
news:5CDBF3A1-A823-4796-8D85-D1C655B66459@.microsoft.com...
>I think as part of your migration to SQL Server you should migrate your
> dynamic sql code to stored procedures, I'm not sure that there is anything
> you can do to make the code you have work the way it is. Having that said
> if
> your going to have to change it you might as well use sp's.
> "Martin" wrote:
>> Hi,
>>
>> I currently have an application that connects to an MS ACCESS database.
>> This
>> application uses an OLEDB connection string for MS ACCESS.
>> Now, I'd like to upsize the application so I converted the db to SQL
>> SERVER
>> and this went well.
>>
>> Next thing I changed the connection string from OLEDB for MS ACCESS to
>> OLEDB
>> for SQL SERVER.
>> I expected this to work resonably well, however I found that it never
>> worked
>> at all.
>> The reason is that I have done all my MS ACCESS queries using dynamic SQL
>> and Parameterized queries like so
>>
>> objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM tblSecurity WHERE
>> UserName=@.UserName AND Secretword=@.Password"
>> This seems to work fine for access, But the OLEDB provider for SQL SERVER
>> complains bitterly about this, for example, attempting to execurte the
>> above
>> query with attached parameters gives me the following error
>>
>> Must declare the variable '@.UserName'.
>>
>> Can anybody please explain why these two database will not work with the
>> same syntax even though I am using an OLEDB connection string / Provider
>> for
>> both.
>>
>>
>> I have included my full code below.
>> Please note that this works with an MS ACCESS OLEDB connection string but
>> NOT an OLEDB SQL SERVER CONNECTION STRING.
>>
>> many thanks in advance.
>>
>> cheers
>>
>> martin.
>> ================================================== ================================================== =====
>>
>>
>>
>>
>>
>> Dim objConn As System.Data.OleDb.OleDbConnection = New
>> System.Data.OleDb.OleDbConnection()
>> Dim objCMD As System.Data.OleDb.OleDbCommand = New
>> System.Data.OleDb.OleDbCommand()
>> Try
>> 'Trace.Warn("Con string",
>> OleDbConnection1.ConnectionString)
>> objConn.ConnectionString() =
>> Application("ConnectionString")
>> objCMD.Connection = objConn
>> objConn.Open()
>> Trace.Warn("Con string", objConn.ConnectionString())
>> objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM
>> tblSecurity WHERE UserName=@.UserName AND Secretword=@.Password"
>> Trace.Warn("Database", "database open")
>> Dim Param1 As System.Data.OleDb.OleDbParameter
>> Dim Param2 As System.Data.OleDb.OleDbParameter
>> Param1 = objCMD.Parameters.Add("@.UserName",
>> TextBox1.Text.Trim())
>> Param2 = objCMD.Parameters.Add("@.Password",
>> Password1.Value.Trim())
>> intNumUsers = objCMD.ExecuteScalar() 'Execute the query
>> 'ERROR THROWN HERE WORKS ON ACCESS BUT NOT SS
>> Trace.Warn("Database", "No database error occured")
>> Catch err As Exception
>> Dim strErrMessage As String
>> strErrMessage = "Exception thrown function
>> btnLogin_Click" &
>> Request.ServerVariables("SCRIPT_NAME") & "<br>"
>> Trace.Write("ERROR", err.Message.ToString)
>> 'Response.End()
>> 'EmailException(err.Message, strErrMessage)
>> Finally
>> If objConn.State = ConnectionState.Open Then
>> Try
>> 'Attempt to close the connection
>> objConn.Close()
>> Catch err As Exception
>> 'Catch any error that may occur
>> Dim strErrMessage As String
>> strErrMessage = "Exception thrown attemping to
>> close
>> after checking the user is in admin. File " &
>> Request.ServerVariables("SCRIPT_NAME") & "<br>"
>> EmailException(err.Message, strErrMessage)
>> End Try
>> End If
>> End Try
>>
>>
>>
>

OLEDB Provider for SQL SERVER + Parameterized Queries

Hi,
I currently have an application that connects to an MS ACCESS database. This
application uses an OLEDB connection string for MS ACCESS.
Now, I'd like to upsize the application so I converted the db to SQL SERVER
and this went well.
Next thing I changed the connection string from OLEDB for MS ACCESS to OLEDB
for SQL SERVER.
I expected this to work resonably well, however I found that it never worked
at all.
The reason is that I have done all my MS ACCESS queries using dynamic SQL
and Parameterized queries like so
objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM tblSecurity WHERE
UserName=@dotnet.itags.org.UserName AND Secretword=@dotnet.itags.org.Password"
This seems to work fine for access, But the OLEDB provider for SQL SERVER
complains bitterly about this, for example, attempting to execurte the above
query with attached parameters gives me the following error
Must declare the variable '@dotnet.itags.org.UserName'.
Can anybody please explain why these two database will not work with the
same syntax even though I am using an OLEDB connection string / Provider for
both.
I have included my full code below.
Please note that this works with an MS ACCESS OLEDB connection string but
NOT an OLEDB SQL SERVER CONNECTION STRING.
many thanks in advance.
cheers
martin.
========================================
====================================
=============================
Dim objConn As System.Data.OleDb.OleDbConnection = New
System.Data.OleDb.OleDbConnection()
Dim objCMD As System.Data.OleDb.OleDbCommand = New
System.Data.OleDb.OleDbCommand()
Try
'Trace.Warn("Con string", OleDbConnection1.ConnectionString)
objConn.ConnectionString() = Application("ConnectionString")
objCMD.Connection = objConn
objConn.Open()
Trace.Warn("Con string", objConn.ConnectionString())
objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM
tblSecurity WHERE UserName=@dotnet.itags.org.UserName AND Secretword=@dotnet.itags.org.Password"
Trace.Warn("Database", "database open")
Dim Param1 As System.Data.OleDb.OleDbParameter
Dim Param2 As System.Data.OleDb.OleDbParameter
Param1 = objCMD.Parameters.Add("@dotnet.itags.org.UserName",
TextBox1.Text.Trim())
Param2 = objCMD.Parameters.Add("@dotnet.itags.org.Password",
Password1.Value.Trim())
intNumUsers = objCMD.ExecuteScalar() 'Execute the query
'ERROR THROWN HERE WORKS ON ACCESS BUT NOT SS
Trace.Warn("Database", "No database error occured")
Catch err As Exception
Dim strErrMessage As String
strErrMessage = "Exception thrown function btnLogin_Click" &
Request.ServerVariables("SCRIPT_NAME") & "<br>"
Trace.Write("ERROR", err.Message.ToString)
'Response.End()
'EmailException(err.Message, strErrMessage)
Finally
If objConn.State = ConnectionState.Open Then
Try
'Attempt to close the connection
objConn.Close()
Catch err As Exception
'Catch any error that may occur
Dim strErrMessage As String
strErrMessage = "Exception thrown attemping to close
after checking the user is in admin. File " &
Request.ServerVariables("SCRIPT_NAME") & "<br>"
EmailException(err.Message, strErrMessage)
End Try
End If
End TryI think as part of your migration to SQL Server you should migrate your
dynamic sql code to stored procedures, I'm not sure that there is anything
you can do to make the code you have work the way it is. Having that said if
your going to have to change it you might as well use sp's.
"Martin" wrote:

> Hi,
> I currently have an application that connects to an MS ACCESS database. Th
is
> application uses an OLEDB connection string for MS ACCESS.
> Now, I'd like to upsize the application so I converted the db to SQL SERVE
R
> and this went well.
> Next thing I changed the connection string from OLEDB for MS ACCESS to OLE
DB
> for SQL SERVER.
> I expected this to work resonably well, however I found that it never work
ed
> at all.
> The reason is that I have done all my MS ACCESS queries using dynamic SQL
> and Parameterized queries like so
> objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM tblSecurity WHERE
> UserName=@.UserName AND Secretword=@.Password"
> This seems to work fine for access, But the OLEDB provider for SQL SERVER
> complains bitterly about this, for example, attempting to execurte the abo
ve
> query with attached parameters gives me the following error
> Must declare the variable '@.UserName'.
> Can anybody please explain why these two database will not work with the
> same syntax even though I am using an OLEDB connection string / Provider f
or
> both.
>
> I have included my full code below.
> Please note that this works with an MS ACCESS OLEDB connection string but
> NOT an OLEDB SQL SERVER CONNECTION STRING.
> many thanks in advance.
> cheers
> martin.
> ========================================
==================================
===============================
>
>
> Dim objConn As System.Data.OleDb.OleDbConnection = New
> System.Data.OleDb.OleDbConnection()
> Dim objCMD As System.Data.OleDb.OleDbCommand = New
> System.Data.OleDb.OleDbCommand()
> Try
> 'Trace.Warn("Con string", OleDbConnection1.ConnectionStrin
g)
> objConn.ConnectionString() = Application("ConnectionString
")
> objCMD.Connection = objConn
> objConn.Open()
> Trace.Warn("Con string", objConn.ConnectionString())
> objCMD.CommandText = "SELECT COUNT(*) AS UserCount FROM
> tblSecurity WHERE UserName=@.UserName AND Secretword=@.Password"
> Trace.Warn("Database", "database open")
> Dim Param1 As System.Data.OleDb.OleDbParameter
> Dim Param2 As System.Data.OleDb.OleDbParameter
> Param1 = objCMD.Parameters.Add("@.UserName",
> TextBox1.Text.Trim())
> Param2 = objCMD.Parameters.Add("@.Password",
> Password1.Value.Trim())
> intNumUsers = objCMD.ExecuteScalar() 'Execute the query
> 'ERROR THROWN HERE WORKS ON ACCESS BUT NOT SS
> Trace.Warn("Database", "No database error occured")
> Catch err As Exception
> Dim strErrMessage As String
> strErrMessage = "Exception thrown function btnLogin_Click"
&
> Request.ServerVariables("SCRIPT_NAME") & "<br>"
> Trace.Write("ERROR", err.Message.ToString)
> 'Response.End()
> 'EmailException(err.Message, strErrMessage)
> Finally
> If objConn.State = ConnectionState.Open Then
> Try
> 'Attempt to close the connection
> objConn.Close()
> Catch err As Exception
> 'Catch any error that may occur
> Dim strErrMessage As String
> strErrMessage = "Exception thrown attemping to clo
se
> after checking the user is in admin. File " &
> Request.ServerVariables("SCRIPT_NAME") & "<br>"
> EmailException(err.Message, strErrMessage)
> End Try
> End If
> End Try
>
>
I agree entirely, you are totally right - If you use SQL SERVER the sp's are
definatly the way to go.
However I would be interested to find out why parameterised queries work
with the OLEDB provider for MS ACCESS but NOT with the OLEDB provider for
SQL SERVER.
"Alien2_51" <dan.billow.remove@.monacocoach.removeme.com> wrote in message
news:5CDBF3A1-A823-4796-8D85-D1C655B66459@.microsoft.com...
>I think as part of your migration to SQL Server you should migrate your
> dynamic sql code to stored procedures, I'm not sure that there is anything
> you can do to make the code you have work the way it is. Having that said
> if
> your going to have to change it you might as well use sp's.
> "Martin" wrote:
>

OleDbConnection seems to kill Session state

I am working on a simple ASP.NET project with access to an MS Access database. I have noticed that any information stored in Session variables (e.g. Session("Test")) as well as any global parameters (declared as Public ... in a vb module) get reset to Nothing upon postback when a connection was opened (the code works just fine otherwise, i.e. when I don't use any Public variables or Session variable). I have sketched the sequence below.

Any suggestions on what might be happening here and how I might be able to work around this?

Thanks in advance,
Rolf

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Me.IsPostBack Then
Session("Test1") = "Test1"
g_test = "Test1"
'both the Session parameter and g_test have the assigned values
...
Call EstablishConnection()
...
Session("Test2") = "Test2"
g_test = "Test2"
'both the Session parameter and g_test have the assigned values
Else
Dim dummy As String
dummy = CStr(Session("Test"))
'both the Session parameter and g_test are set to Nothing
End If
End SubI found out that there is an issue with where exactly the database file is located. If it located in the /bin folder of the application, ASP.NET seems to draw reset the session (see this link (http://www.dotnet247.com/247reference/msgs/58/290316.aspx)). I now moved the database file to a different folder and everything is working just fine, Session variables and public variables maintain their values.
That's because if anything changes in the /BIN folder the ASP.NET run time assumes the project needs recompiled. You probably also noticed a marked increase in application performance after making your move.
A leftover from winforms programming perhaps? :D

OleDbConnection Security Exception

I wish to allow ASP.NET pages to make connections to Access databases using
OleDBConnection.

The only way I have been able to make this functionality work has been to
set:

Unrestricted="true"

In the <PermissionSet> property applying to ASP.NET pages, otherwise I get:

Security Exception
Description: The application attempted to perform an operation not allowed
by the security policy. To grant this application the required permission
please contact your system administrator or change the application's trust
level in the configuration file.

Exception Details: System.Security.SecurityException: Request failed.

I do not wish to run ASP.NET pages in an unrestricted security policy, I
would be grateful if you could inform me which permissions I must grant to
allow the use of OleDBConnection. I have granted unrestricted
OleDbPermission, FileIOPermission and RegistryPermission but to no avail.Nothing you can do about it.

ASP.NET requires Full Trust in order to allow OleDb, Odbc and OracleClient connections.

From the docs:

"This class is intended for future use when the .NET Framework Data Provider for OLE DB is enabled for partial trust scenarios. The .NET Framework Data Provider for OLE DB currently requires FullTrust permission. At present, using the OleDbPermission class has no effect."

Regards,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

--
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nothing you can do about it.

ASP.NET requires Full Trust in order to allow OleDb, Odbc and OracleClient connections.

From the docs:

"This class is intended for future use when the .NET Framework Data Provider for OLE DB is enabled for partial trust scenarios. The .NET Framework Data Provider for OLE DB currently requires FullTrust permission. At present, using the OleDbPermission class has no effect."

Regards,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

--
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/

OleDbException executing reader on Access stored view

I had a strange error in asp.net when try to execute a simple select
statement like "Select * From ViewName" if the stored view contains a where
clause.
The connection is made to an Access database using System.Data.OleDb objects
and Jet 4.0 oledb provider.
The same code works fine in windows form application.
Removing the where clause from the stored view or adding ASPNET user into
"Power Users" or "Administrators" groups, all works also in asp.net.
My first idea was a security/permission problem, but it is strange that all
properly works without the where clause.

The error happens on Win xp sp2 with .NET 1.1 sp1 and don't happens on Win
xp sp1 with .NET 1.1 sp1.

???
Some ideas?

Thanks so much for your help, Marco.Exceptions have messages. Odd that you danced all around the exception
without managing to mention what exactly it IS. How about it?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Marco Frontini" <iunknown@.libero.it> wrote in message
news:ucslziM%23EHA.2156@.TK2MSFTNGP10.phx.gbl...
>I had a strange error in asp.net when try to execute a simple select
>statement like "Select * From ViewName" if the stored view contains a
>where clause.
> The connection is made to an Access database using System.Data.OleDb
> objects and Jet 4.0 oledb provider.
> The same code works fine in windows form application.
> Removing the where clause from the stored view or adding ASPNET user into
> "Power Users" or "Administrators" groups, all works also in asp.net.
> My first idea was a security/permission problem, but it is strange that
> all properly works without the where clause.
> The error happens on Win xp sp2 with .NET 1.1 sp1 and don't happens on Win
> xp sp1 with .NET 1.1 sp1.
> ???
> Some ideas?
> Thanks so much for your help, Marco.
A generic "Internal OLE Automation Error" isn't so usefull.

"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> ha scritto nel messaggio
news:O8pWebN%23EHA.1296@.TK2MSFTNGP10.phx.gbl...
> Exceptions have messages. Odd that you danced all around the exception
> without managing to mention what exactly it IS. How about it?
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Neither a follower nor a lender be.
> "Marco Frontini" <iunknown@.libero.it> wrote in message
> news:ucslziM%23EHA.2156@.TK2MSFTNGP10.phx.gbl...
>>I had a strange error in asp.net when try to execute a simple select
>>statement like "Select * From ViewName" if the stored view contains a
>>where clause.
>> The connection is made to an Access database using System.Data.OleDb
>> objects and Jet 4.0 oledb provider.
>> The same code works fine in windows form application.
>> Removing the where clause from the stored view or adding ASPNET user into
>> "Power Users" or "Administrators" groups, all works also in asp.net.
>> My first idea was a security/permission problem, but it is strange that
>> all properly works without the where clause.
>>
>> The error happens on Win xp sp2 with .NET 1.1 sp1 and don't happens on
>> Win xp sp1 with .NET 1.1 sp1.
>>
>> ???
>> Some ideas?
>>
>> Thanks so much for your help, Marco.
>>

OleDbException executing reader on Access stored view

I had a strange error in asp.net when try to execute a simple select
statement like "Select * From ViewName" if the stored view contains a where
clause.
The connection is made to an Access database using System.Data.OleDb objects
and Jet 4.0 oledb provider.
The same code works fine in windows form application.
Removing the where clause from the stored view or adding ASPNET user into
"Power Users" or "Administrators" groups, all works also in asp.net.
My first idea was a security/permission problem, but it is strange that all
properly works without the where clause.
The error happens on Win xp sp2 with .NET 1.1 sp1 and don't happens on Win
xp sp1 with .NET 1.1 sp1.
'?
Some ideas?
Thanks so much for your help, Marco.Exceptions have messages. Odd that you danced all around the exception
without managing to mention what exactly it IS. How about it?
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.
"Marco Frontini" <iunknown@.libero.it> wrote in message
news:ucslziM%23EHA.2156@.TK2MSFTNGP10.phx.gbl...
>I had a strange error in asp.net when try to execute a simple select
>statement like "Select * From ViewName" if the stored view contains a
>where clause.
> The connection is made to an Access database using System.Data.OleDb
> objects and Jet 4.0 oledb provider.
> The same code works fine in windows form application.
> Removing the where clause from the stored view or adding ASPNET user into
> "Power Users" or "Administrators" groups, all works also in asp.net.
> My first idea was a security/permission problem, but it is strange that
> all properly works without the where clause.
> The error happens on Win xp sp2 with .NET 1.1 sp1 and don't happens on Win
> xp sp1 with .NET 1.1 sp1.
> '?
> Some ideas?
> Thanks so much for your help, Marco.
>
A generic "Internal OLE Automation Error" isn't so usefull.
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> ha scritto nel messaggio
news:O8pWebN%23EHA.1296@.TK2MSFTNGP10.phx.gbl...
> Exceptions have messages. Odd that you danced all around the exception
> without managing to mention what exactly it IS. How about it?
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Neither a follower nor a lender be.
> "Marco Frontini" <iunknown@.libero.it> wrote in message
> news:ucslziM%23EHA.2156@.TK2MSFTNGP10.phx.gbl...
>

OleDbException: Data type mismatch in criteria expression.

Using Access db with VS2008 (ASP.NET/VB.NET)...
On the INSERT command I get this error: System.Data.OleDb.OleDbException:
Data type mismatch in criteria expression.
I haven't found a solution yet in my research. Any idea what I might be
missing?
**************
Datasource setup as follows:
<asp:AccessDataSource ID="AccessDataSource1"
runat="server"
DataFile="~/BeachFuneral.mdb"
InsertCommand="INSERT INTO [ObitComments]
([ObitId], [CommentBy], [CommentEmail], [CommentRelation],
[CommentApproved], [CommentDateTime], [ObitComment]) VALUES (?, ?, ?, ?, ?,
?, ?)" >
<InsertParameters>
<asp:Parameter Name="ObitId" />
<asp:Parameter Name="CommentBy" />
<asp:Parameter Name="CommentEmail" />
<asp:Parameter Name="CommentRelation" />
<asp:Parameter Name="CommentApproved" />
<asp:Parameter Name="CommentDateTime" />
<asp:Parameter Name="ObitComment" />
</InsertParameters>
</asp:AccessDataSource>
**************
Code to insert as follows:
With Me.AccessDataSource1
.InsertParameters("ObitId").DefaultValue =
Request.QueryString("Id")
.InsertParameters("CommentBy").DefaultValue =
Me.txtFullName.Text
.InsertParameters("CommentEmail").DefaultValue =
Me.txtEmail.Text
.InsertParameters("CommentRelation").DefaultValue =
Me.txtRelationship.Text
.InsertParameters("CommentApproved").DefaultValue = True
.InsertParameters("CommentDateTime").DefaultValue = Now.ToString
.InsertParameters("ObitComment").DefaultValue =
Me.txtComment.Text
End With
Try
Me.AccessDataSource1.Insert()
Catch ex As Exception
Response.Write(ex.ToString)
Exit Sub
Finally
' if ok then move on...
Response.Redirect("Obit.aspx?Id=" & Request.QueryString("Id"))
End TryYou have not identified what data types your database is using, either in
this message, or in your code. However, you are attemtping to insert all
string values (text data type), with the exception of one field
(CommentApproved) which you are inserting a boolean value into. So, unless
all of the fields in the table are text except for that one, you would
certainly get that exception.
HTH,
Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
"Bobby Edward" <test@.test.com> wrote in message
news:OkUo0QofIHA.288@.TK2MSFTNGP02.phx.gbl...
> Using Access db with VS2008 (ASP.NET/VB.NET)...
> On the INSERT command I get this error: System.Data.OleDb.OleDbException:
> Data type mismatch in criteria expression.
> I haven't found a solution yet in my research. Any idea what I might be
> missing?
> **************
> Datasource setup as follows:
> <asp:AccessDataSource ID="AccessDataSource1"
> runat="server"
> DataFile="~/BeachFuneral.mdb"
> InsertCommand="INSERT INTO [ObitComments]
> ([ObitId], [CommentBy], [CommentEmail], [CommentRelation],
> [CommentApproved], [CommentDateTime], [ObitComment]) VALUES (?, ?, ?, ?,
> ?, ?, ?)" >
> <InsertParameters>
> <asp:Parameter Name="ObitId" />
> <asp:Parameter Name="CommentBy" />
> <asp:Parameter Name="CommentEmail" />
> <asp:Parameter Name="CommentRelation"
> />
> <asp:Parameter Name="CommentApproved"
> />
> <asp:Parameter Name="CommentDateTime"
> />
> <asp:Parameter Name="ObitComment" />
> </InsertParameters>
> </asp:AccessDataSource>
> **************
> Code to insert as follows:
> With Me.AccessDataSource1
> .InsertParameters("ObitId").DefaultValue =
> Request.QueryString("Id")
> .InsertParameters("CommentBy").DefaultValue =
> Me.txtFullName.Text
> .InsertParameters("CommentEmail").DefaultValue =
> Me.txtEmail.Text
> .InsertParameters("CommentRelation").DefaultValue =
> Me.txtRelationship.Text
> .InsertParameters("CommentApproved").DefaultValue = True
> .InsertParameters("CommentDateTime").DefaultValue =
> Now.ToString
> .InsertParameters("ObitComment").DefaultValue =
> Me.txtComment.Text
> End With
> Try
> Me.AccessDataSource1.Insert()
> Catch ex As Exception
> Response.Write(ex.ToString)
> Exit Sub
> Finally
> ' if ok then move on...
> Response.Redirect("Obit.aspx?Id=" & Request.QueryString("Id"))
> End Try
>
>

Wednesday, March 21, 2012

OleDbParameters, Pls help...

Hi, im trying to insert this paragraph to Access Db,

Miniplast <T-Piece> Welding Machine

But it show me error as below:
Server Error in '/' Application.
------------------------

A potentially dangerous Request.Form value was detected from the client (tb0="...niplast 2 <T-Piece> Welding Ma...").
Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (tb0="...niplast 2 <T-Piece> Welding Ma...").

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (tb0="...niplast 2 <T-Piece> Welding Ma...").]
System.Web.HttpRequest.ValidateString(String s, String valueName, String collectionName) +230
System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, String collectionName) +99
System.Web.HttpRequest.get_Form() +121
System.Web.UI.Page.GetCollectionBasedOnMethod() +70
System.Web.UI.Page.DeterminePostBackMode() +47
System.Web.UI.Page.ProcessRequestMain() +2106
System.Web.UI.Page.ProcessRequest() +218
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87

Here is my code


Dim strsql as string= "INSERT INTO ToolNAccessories (Name, Descrip, Price) VALUES" & _
"( @dotnet.itags.org.Params0, @dotnet.itags.org.Params1, @dotnet.itags.org.Params2)"
Dim objCmd as New OleDbCommand(StrSql, Conn)
Dim Objparam as OleDbParameter

With ObjCmd.Parameters:
.Add(New OleDbParameter("@dotnet.itags.org.Params0", Tb0.Text))
.Add(New OleDbParameter("@dotnet.itags.org.Params1", Tb1.Text))
.Add(New OleDbParameter("@dotnet.itags.org.Params2", Tb2.Text))
End With
Conn.Open()
ObjCmd.ExecuteNonQuery()
Conn.Close()

This piece of code was working very well until i insert


Miniplast <T-Piece> Welding Machine

This sound like Sql injection... how can it be... im using parameters to prevent it already right?

Any idea what happened? Pls guard me on tis..

Thanks in advance
life's NgOn the page, in the @.page directive, add ValidateRequest="false". This will allow the < and > character in posted data, but you should then check for script injection.
Thanks douglas,

oh my God.... now i then realize there is sooo much injections we gonna deal with... :(

Mr douglas, i dont think im going to set validateRequest="false"... but I having some questions in my mind..

1. Will my previous error let any attacker getting some clues to proceed their job?

2. Can i try some "weird" characters like <>)*&%$^&* for some user's input on any website? is that illegal? i just wish to try out see whether the web application is secure from this aspect.. will that made a web server down or something?

Best Regards
life's Ng
Hi Douglas,

I wonder if i set validateRequest="false" , all i need to check is script injection using "Server.HtmlEncode" is tat correct? Anything else i need to consider?

Regards
life's Ng
If it is acceptable to have users enter < or >, then you will need to set ValidateRequest="false". Failing that, you should think about handling the error in a somewhat more elegant way. I am not totally certain that will address all the issues. Anyone else who has looked at this more closely?