Archive for February, 2016

Resetting an Oracle password through .NET

In case you ever want to reset an Oracle password through ASP.NET, without worrying about pesky things like SQL injection attacks or any other security holes (what could possibly go wrong…)

public void ResetPassword (string pUserName, string pPassWord, string connString) {
       string query = "alter user " + pUserName + " identified by " + pPassWord;
       using (OracleConnection conn = new OracleConnection(connString)) {
           using (OracleCommand comm = new OracleCommand(query, conn)) {
              conn.Open();
              comm.ExecuteNonQuery();
           }
       }
}
Advertisements

1 Comment

“Excel found unreadable content” error

I was exporting an Excel document using OpenXml, and added a new cell to be added to the export:

Cell newCell = new Cell() { CellReference = “A” + rowIndex };
r.InsertAt(newCell, cellIndex);
newCell.CellValue = new CellValue(item[i].Description);
newCell.DataType = new EnumValue<CellValues>(CellValues.Number);
cellIndex++;

After making this change, I received the message “Excel found unreadable content in ‘My Excel file.xlsx’. Do you want to recover the contents of the workbook?

Error

The problem was that I was attempting to format the cell as a number when it was actually a string. I modified the line that set the cell DataType, and it was fine:

newCell.DataType = new EnumValue<CellValues>(CellValues.String);

Leave a comment

“Grant option does not exist for view” error in Oracle

I had an MVC project that was using Entity Framework (or THE Entity Framework, if you prefer, Ohio State fans) against an Oracle database. I was jumping into the project and had just created a new Oracle user to limit access the only the tables I needed instead of using a more powerful account that could do whatever it wanted. So I was granting SELECT access to those tables, and also some views. I hit one particular view that gave me this error:

 ORA-01720: grant option does not exist for 'Parks.Coaster_View'

Trying to grant permissions first to the tables that the view referenced, then granting them to the view, didn’t work either. What I had to do, as explained in this article, was to grant select access to the schema owner of the view to the table itself:

grant select on OtherSchema.TableThatViewReferences to Parks with grant option;

After that, my grant statement on the view worked.

Leave a comment

Display a PDF in an ASP.NET page

It was surprisingly simple to display a PDF file in an ASP.NET page. First, in the .aspx page, I cleared out all the code except for the first line. Here is the complete page:

 <%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”PdfDisplay.aspx.cs” Inherits=”MyProject.PdfDisplay” %>

 In the code-behind file, I added the following to the Page_Load event:

Response.Clear();
string filePath = @”C:\Documents\MyReport.pdf”;
Response.ContentType = “application/pdf”;
Response.WriteFile(filePath);

Leave a comment