Update Query from ASP.NET to .MDB Failing - sql

Context:
I have an update query for a Microsoft Access DB that keeps failing. The query works when executed from within my DB, but fails when executed from my CodeFile for my .aspx page.
I have ensured that:
My App_Data folder has write permissions (via IUSR)
My DB is not 'Read Only'
My query syntax is correct
Does anyone have any advice on what I might be missing? Thank you!!
Code:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Imports System.Data.OleDb
Partial Class jsDB
Inherits System.Web.UI.Page
Private con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\Dustin\App_Data\FAQ.accdb")
Public Sub Page_Load(sender as object, e as System.EventArgs)
If request.QueryString("type") = "helpful" Then
Dim cleanID as string
cleanID = request.querystring("id")
If IsNumeric(cint(cleanID)) Then 'Make sure QueryString hasn't been tampered with
Dim sql as string
sql = "UPDATE QUESTION SET helpful=helpful+1 WHERE questionID=" & cleanID
Dim cmd As New OleDbCommand(sql, con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Response.write("Success")
else
Response.write("Invalid ID")
end if
else
Response.write("No recognized type")
end If
End Sub
End Class
Error:
Server Error in '/' Application.
Operation must use an updateable query.
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: Operation must use an updateable query.
Source Error:
Line 27:
Line 28: con.Open()
Line 29: cmd.ExecuteNonQuery()
Line 30: con.Close()
Line 31:
Source File: C:\Dustin\FAQDB.aspx.vb Line: 29
Stack Trace:
[OleDbException (0x80004005): Operation must use an updateable query.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1102900
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +189
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +162
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +107
jsDB.Page_Load(Object sender, EventArgs e) in C:\Dustin\FAQDB.aspx.vb:29
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

This help page addresses the error you are receiving:
https://support.microsoft.com/en-us/kb/175168
It looks like either youre not opening the connection in the right mode (Mode 3 in this case) or the "table" you are updating has conditions which prevent you from updating it. I'd bet though that changing your Mode to 3 will resolve the issue.

There are several things done wrong here that may help you resolve this and other issues in the future.
IsNumeric(cint(cleanID)) - The IsNumeric() on CInt() is irrelevant. The CInt will either return a System.Int32 or an error. You should just do the IsNumeric() and if you want to know if it is an Int32, then do a Int32.TryParse() on it.
Your command should be parameterized to avoid injection and to avoid passing the wrong data type. For example, I don't know if questionID is a string (which makes your syntax wrong) or if it is an int32. But, a parameterized command would and will supply the correct syntax to your SQL. You can find thousands of example on ho to do this so I will not explain it again here.
The last item, and likely the solution, MS Access queries like to end in a semicolon (;). Seems like I have had issues in the past with not having them in my UPDATE commands for MS Access.
As a side-note. MS Access is terrible about handling multiple connections so leaving them open because of errors will cause you HUGE problems. Be sure that all database calls have proper error handling and if you can put them in a USING block, even better.

Shout-out to #Steve for being such a big help on this.
I had several issues here. While I'm sure there are many issues which could produce the error I was experiencing, here's what resolved it for me:
Created a new application pool in IIS and gave this new pool write permissions to my App_Data folder
Assigned this new app pool to my application
Modified the new app pool under advanced settings to allow 32 bit applications
As of right now, the 'Microsoft.ACE.OLEDB.12.0' provider only works as 32-bit. Changing my application pool to allow 32 bit applications resolved the issue.
Thanks all for your input!

Related

Orchard- All Indexes Rebuild Failing

I have been having an issue where Indexes for Search have been failing for a while it seemed like new indexes weren't getting created. I went to rebuild the Search index using that rebuild button, and all the documents that were previously indexed were no longer indexed.
I followed this article without results: Orchard - Search & Indexing issue
This did not work. I think probably because
App_data\Sites\Default\Search.settings.xml
doesn't get generated in the first place. I do however see a file:
App_data\Sites\Default\Search.settings.xml.lock
I believe the Orchard.Indexing.Services.IndexingTaskExecutor UpdateIndexBatch method is failing because my impression is the lock file would be created and then deleted if it was working. Here is a possibly relevant error:
2021-01-08 00:00:41,174 [48] Orchard.Exceptions.DefaultExceptionPolicy - Default - An unexpected exception was caught
(null)
System.NullReferenceException: Object reference not set to an instance of an object.
at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options, QueryHints hints)
at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options)
at Orchard.Indexing.Services.IndexingTaskExecutor.b__0(ContentItemVersionRecord versionRecord)
at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Linq.Enumerable.<DistinctIterator>d__641.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Orchard.Indexing.Services.IndexingTaskExecutor.BatchIndex(String indexName, String settingsFilename, IndexSettings indexSettings) at Orchard.Indexing.Services.IndexingTaskExecutor.UpdateIndexBatch(String indexName) at Orchard.Indexing.Services.UpdateIndexScheduler.UpdateIndex(String indexName) at Orchard.Events.DelegateHelper.<>c__DisplayClass2b2.b__2a(Object target, Object[] p)
at Orchard.Events.DefaultOrchardEventBus.TryInvokeMethod(IEventHandler eventHandler, Type interfaceType, String messageName, String interfaceName, String methodName, IDictionary2 arguments, IEnumerable& returnValue) at Orchard.Events.DefaultOrchardEventBus.TryNotifyHandler(IEventHandler eventHandler, String messageName, String interfaceName, String methodName, IDictionary2 eventData, IEnumerable& returnValue)
Another error I see that I believe is related to the issue seems to occur in Orchard.Indexing.Handlers.InfosetFieldIndexingHandler
2021-01-08 00:00:02,236 [48] Orchard.ContentManagement.DefaultContentManager - Default - NullReferenceException thrown from IContentHandler by Orchard.Indexing.Handlers.InfosetFieldIndexingHandler
(null)
System.NullReferenceException: Object reference not set to an instance of an object.
at Orchard.Fields.Fields.DateTimeField.get_DateTime()
at Orchard.Fields.Drivers.DateTimeFieldDriver.b__15(DateTimeField field)
at Orchard.ContentManagement.Handlers.DescribeMembersContext.Enumerate[TField](Func1 enumerate) at Orchard.Fields.Drivers.DateTimeFieldDriver.Describe(DescribeMembersContext context) at Orchard.ContentManagement.Drivers.ContentFieldDriver1.Orchard.ContentManagement.Drivers.IContentFieldDriver.Describe(DescribeMembersContext context)
at Orchard.Indexing.Handlers.InfosetFieldIndexingHandler.<.ctor>b__0(IndexContentContext context, InfosetPart cp)
at Orchard.ContentManagement.Handlers.ContentHandler.InlineStorageFilter1.Indexing(IndexContentContext context, TPart instance) at Orchard.ContentManagement.Handlers.StorageFilterBase1.Orchard.ContentManagement.Handlers.IContentStorageFilter.Indexing(IndexContentContext context)
at Orchard.ContentManagement.Handlers.ContentHandler.Orchard.ContentManagement.Handlers.IContentHandler.Indexing(IndexContentContext context)
at Orchard.ContentManagement.DefaultContentManager.<>c__DisplayClass99.b__97(IContentHandler handler)
at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable1 events, Action1 dispatch, ILogger logger)
To note, I did try to generate a new index and just have it index news articles. This did not work, or generate the settings.xml file either.
Is there a database location that I should be looking at that could be containing null dates, or should I be looking elsewhere? Any help would be greatly appreciated.
Edit: It has been two days and no responses, so I made a post with updated details on git (in case someone is looking for an answer to the same question, and in case git hub has an answer git hub issue)
The solution was found. There was some null data within ContentItemRecord. The null Data and ContentType_id resulted in no indexes being built even unrelated index.
Here is the query we used to find the bad data. The xxxxxx would need to be replaced by whatever prefix is associated with your table, but gives you an idea what to do.
SELECT *
FROM [dbo].[xxxxxx_Orchard_Framework_ContentItemVersionRecord] civr
LEFT JOIN [dbo].[xxxxxx_Orchard_Framework_ContentItemRecord] cir ON civr.ContentItemRecord_id = cir.Id
LEFT JOIN [dbo].[xxxxxx_Orchard_Framework_ContentTypeRecord] ctr ON cir.ContentType_id = ctr.Id
WHERE cir.Id IS NULL OR cir.Data IS NULL OR ctr.Id IS NULL

OracleDataAdapter Started Returning error ORA-00942: table or view does not exist

Development Environment:
VB.NET
.net 4.5
ODP.NET
Oracle 11g
Hi there I have a weird problem, code in my development environment which has been working for a good number of years has suddenly stopped working. The OracleDataAdapter returns the error ORA-00942: table or view does not exist. However there is nothing wrong with the SQL that is passed to the adapter, the SQL executes successfully in SQLDeveloper. It looks like the issue is with my VS development environment, as a previously compiled version of the application runs as normal. I have re-compiled the entire VS solution and re-booted my development machine and then re-compiled without any joy.
The exact error returned is shown in the following log entry:
12|09:43:50|DOMAIN\USER|Trace| Oracle.DataAccess.Client.OracleException ORA-00942: table or view does not exist
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at QueryMain.uxBWFetch_DoWork(Object sender, DoWorkEventArgs e) in d:\users\USER\Documents_VSSWorkArea\PSALERTS 2017\PSALERTS Client\Query\QueryMain.vb:line 677
Here is the code which generates the error:
Dim myDataset As New DataSet
Dim myUtils As New Utils
_myConnection = New OracleConnection
_myConnection.ConnectionString = _connectStr
Try
_myDataAdapter = New OracleDataAdapter(SQLStatement, _myConnection)
_myDataAdapter.Fill(myDataset)
_myConnection.Close()
Catch ex As Exception
Throw
Finally
CType(_myConnection, IDisposable).Dispose()
End Try
Return myDataset
GC.Collect()
The error is generated when we try to fill the dataset:
_myDataAdapter.Fill(myDataset)
If anyone has encountered this situation could you please let me know, as it is driving me to distraction!!!
Kind Regards
Paul J.
Well now, don't I feel stupid. Turns out although my intention was to develop against our test database, the SQL generated within the code contained a hardcoded connect string which was pointing at production, and of course the code contains references to new tables which are not in production, hence the error message... DOH...

Why is "using" seemingly rejected in one function, but okay in another?

With this code:
Protected Function GetArgValsForCompanyName(coName As String) As String()
Dim args(2) As String
Using con As New SqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"),
cmd As New SqlCommand("select Unit, MemberNo, CustNo from Customers WHERE CompanyName = #CoName", con)
con.Open()
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("#CoName", SqlDbType.VarChar, 50).Value = coName
Using reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
args(0) = reader.Item(0).ToString()
args(1) = reader.Item(1).ToString()
args(2) = reader.Item(2).ToString()
End While
End Using
End Using
Return args
End Function
...I get:
Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30203: Identifier expected.
Source Error:
Line 94: Dim args(2) As String
Line 95:
Line 96: Using con As New SqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"),
Line 97: cmd As New SqlCommand("select Unit, MemberNo, CustNo from Customers WHERE CompanyName = #CoName", con)
Line 98:
Source File: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_categoryadmin.aspx.vb Line: 96
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
So, the "using con" line is implicated as the problem. I commented out most of the code to just return some random values, and it works fine.
However, there is another "Using" being used: the Button1_Click event handler uses a using. Does it not complain only because the button has not been clicked?
Actually, when I click the button, I do get an error, but it's not about the using; it's because I apparently have too many controls on the form that the button deals with (thousands or label/checkbox pairs, in fact):
Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------
Operation is not valid due to the current state of the object.
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.InvalidOperationException: Operation is not valid due to the current state of the object.
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:
[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +4198079
System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +60
System.Web.HttpRequest.FillInFormCollection() +189
[HttpException (0x80004005): The URL-encoded form data is not valid.]
System.Web.HttpRequest.FillInFormCollection() +11196408
System.Web.HttpRequest.get_Form() +119
System.Web.TraceContext.InitRequest() +1188
System.Web.TraceContext.VerifyStart() +133
System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +11307449
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +452
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
So is it really the "using" that's the problem in the first block of code? Is there a way to still use it, or do I need to revert to the olde-[fangl,fashion]ed way of creating objects?
In VB.NET, the line continuation character allows to treat two lines as one from the point of view of the compiler. This character is the underscore and should be the last one on the line.
This requirement has been largely removed by latest version of VB.NET Compiler that has enough intelligence to understand where the statements end.
For example in LinqPAD 5.10 there is no need to use this character between the two using statement.
Instead, It seems that your current compiler cannot understand this and adding the continuation character should solve the problem
Using con As New SqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"), _
cmd As New SqlCommand("select Unit, MemberNo, CustNo from Customers WHERE CompanyName = #CoName", con)

MQQueueManager Constructor throwing FileNotFoundException

I have the following vb.net code:
Imports IBM.WMQ
[...]
MQEnvironment.Hostname = hostName
MQEnvironment.Port = portNumber
MQEnvironment.Channel = channelName
queueManager = New MQQueueManager(queueManagerName) ' error here
which is throwing the following error:
System.IO.FileNotFoundException occurred
FileName=C:\Users\User\Documents\Visual Studio 2012\Projects\[...]\bin\Debug\mqclient.ini
HResult=-2147024894
Message=Could not find file 'C:\Users\User\Documents\Visual Studio 2012\Projects\[...]\bin\Debug\mqclient.ini'.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
I am not using any ini files in the construction of my queue manager, so does anyone have any idea what's going on - why is it even looking for one, and why in the same directory as the program? I have installed the MQ client, and afaik I have all the environmental variables, etc. set up properly.
Thanks for any help you can give
Is that an unhandled or a first chance exception? Internally, the MQ .net layer will try to read a MQClient.ini but should function quite happily without it. It reads the file for compatibility with the C client, and can handle some of the MQClient.ini stanzas. I would not have expected an absence of such a file to cause problems, but it will try to open it internally. Was that the full callstack, as I'd have expected some MQ libraries on the stack otherwise.

printing pdf using ghostscript via IIS

I referred this code snippet (http://stackoverflow.com/questions/2599925/how-to-print-pdf-on-default-network-printer-using-ghostscript-gswin32c-exe-she) and it worked very well. i can able to print a file silently from my wcf service.
But am getting a problem if i run this via IIS.
means "http://localhost:5030/mywcf" work perfectly.
if i change it to "http://172.16.16.1/mywcf" then am facing the following error. here is the stack trace.
-----------------------------------------------------
[06-18-12 03:38:48] GetSignoff(): The handle is invalid : at System.Diagnostics.Process.CreatePipeWithSecurityAttributes(SafeFileHandle& hReadPipe, SafeFileHandle& hWritePipe, SECURITY_ATTRIBUTES lpPipeAttributes, Int32 nSize)
at System.Diagnostics.Process.CreatePipe(SafeFileHandle& parentHandle, SafeFileHandle& childHandle, Boolean parentInputs)
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at XX.XX.PrintPDF.PrintVSPDF(String ghostScriptPath, Int32 numberOfCopies, String printerName, String pdfFileName) in D:\XX\Code\Server_MU\eBusiness\Business\PrintPDF.cs:line 551
at XX.Business.PrintPDF.Print(String patientId, String reportName, String loginId, String mailMessageId, String deviceId, String facilityId, String noteId) in D:\XX\Code\Server_MU\XX\Business\PrintPDF.cs:line 498
-------
and then i tried to execute the same command generated via cmd.exe which is working fine. any hint might be helpful.
thanks in advance.
rgds,
pa'1'
for this i got an work around. the post i did here for the different logic. holds goood for this requirement also.
html or pdf printing on server side c#
Regards,
Pavan N