Entity Framework error: ‘The underlying provider failed on Open’

I was using the Oracle.ManagedDataAccess DLL to reference an Oracle database  using Entity Framework. However, attempting this was returning the error “The underlying provider failed on Open” when my object list was being populated:

List<COASTER> coasters = context.COASTER.Where(c => c.PARK== "Cedar Point").ToList();

The issue came down to my connection string format. When trying to use the normal format that we’ve come to know and love, I’d encounter the problem. The format I’m talking about is:

metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string='DATA SOURCE=ScottServer;PASSWORD=mypw;USER ID=scott'

However, when I switched to the format that you see in the tnsnames.ora file, I had better results. So good, in fact, that it actually worked:

metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string='Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=my-server)(PORT = 1521))(CONNECT_DATA=(SERVICE_NAME=testdb.www.wunderhund.com)));User Id=scott;Password=mypw;'
Advertisements

Leave a comment

Error opening AVD Manager: Failed to execute Android.bat

I had delved into Xamarin, belatedly entering the world of mobile development. I needed to open the Android Virtual Device (AVD) manager to configure some virtual devices to really get the fun started. However, when I went into my installation folder for the AVD manage (C:\Program Files (x86)\Android\android-sdk\tools\lib on my system) and running the executable, “AVD Manager.exe”, I got the horrible message “Failed to execute tools\android.bat: The system cannot find the file specified”:

android.bat error

Normally, I weep inconsolably when these types of things happen to me, but this time I decided to try to figure it out. And what I discovered what that if I moved to the “AVD Manager.exe” executable to the android-sdk root folder, it worked! If you’re playing at home, the folder I moved it to was C:\Program Files (x86)\Android\android-sdk. Look at that beautiful program:Manager

Another note: On my system, I had to run the executable as an administrator, but your mileage may vary.

Leave a comment

Unable to load the specified metadata resource

I ran into this dastardly error while working on a utility to mass-update connection strings: Unable to load the specified metadata resource.

The problem was the Entity Framework connection string. Take this connection string, which uses an Oracle format:

metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string='Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle-host)(PORT = 1521))(CONNECT_DATA=(SERVICE_NAME=server-name)));User Id=Snoopy;Password=CharlieBrown;'

In three different places, you see the string “Models.Model1”. This is where my attempt went wrong. Different applications have different model names, so while this application has “Models.Model1”, another may have a different, equally creative name like “Models.Model2”. Once I corrected this, my connection worked.

Leave a comment

jQuery autocomplete appears behind Bootstrap modal window

I sure do love those Bootstrap modal popup windows. I use them all the time. They make me feel cool when I use them, and increase my self-esteem greatly. It’s like getting a participation medal when you’re the last place team in soccer, or a more fun sport.

Almost as much as modal popups, I love jQuery autocomplete lists, where you can enter a bit of text and have results returned from the database. Wow, those are fun to play around with. And users love them, too.

Alas, when I tried to bring my two favorite coding snippets together like a Reese’s peanut butter cup, things didn’t turn out well. Here is what the results looked like:

Completely unacceptable – half my list is hidden, and the rest are basically greyed-out. There was much sorrow and gnashing of teeth.

The key to fixing it was the “ui-front” class of the jQuery-ui.css file. Who knew such a small class could bring such happiness? To use the class in this instance, I needed to attach it to the DIV tag containing my textbox, like so:

<div id=”addEmployeeModal” class=”modal fade” role=”dialog”>
   <div class=”modal-dialog”>
      <div class=”modal-content”>
         <div class=”modal-header”>
            <button id=”modalClose” type=”button” class=”close” data-dismiss=”modal”>&times;</button>
<h4 class=”modal-title text-center”>Add employee</h4>
</div>
<div class=”modal-body ui-front“>
@Html.TextBox(“Employee”, null, new { @class = “form-control” })
<input type=”button” value=”Save” onclick=”functionToCallAutocomplete()  />
<
/div>
</div>
</div>
</div>

Now you, too, can enjoy the peanut butter and chocolate joy of using a Bootstrap modal popup and jQuery autocomplete controls.

Leave a comment

The MVC model is null when posting

I had an MVC view that I was using to update my data using a POST method by using a Bootstrap modal popup window. Everything seemed fine, but when I put a breakpoint in my controller action, my model was null. My very simple action:

       [HttpPost]
       public ActionResult Update(Coaster model) {
           return View();
       }

I’m going to give away the ending. The problem was that my form didn’t have the “name” property attached to the “input” tag. I thought the “id” property would be enough to send my model from the view to the controller, but it wasn’t. So instead of this:

<input type="text" id="Code" class="form-control" />

I had to have this:

<input type="text" id="Code" name="Coaster" class="form-control" />


			

Leave a comment

jQuery DatePicker – Removing time from a DatePicker control

I had an MVC view with a TextBox control binding to a model property

@Html.TextBoxFor(model => model.Date, String.Empty, new { @class = "form-control" })

This control was bound to a jQuery DatePicker control:

    $(document).ready(function () {
        $("#Date").datepicker({
            minDate: 0
        });
    });

My problem was that when the model was bound from the database, the DatePicker would also show the time, not just the date like I wanted:

 

 

 

 

 

 

 

 

The fix for this is to make the second parameter a format string with only the date:

@Html.TextBoxFor(model => model.IssueDate, "{0:d}", new { @class = "form-control" })

Leave a comment

Updating an Oracle LONG column

Want to update an Oracle LONG value? Having problems? Well, you’re in luck. Do update the field, run this bit of code. Yes, it’s not an lovely as a one-line UPDATE statement, but sometimes, you have to do it the ugly way:

DECLARE
 coasterDesc varchar2(5000); 
BEGIN
 coasterDesc := 'Some really, really, REALLY long text goes here.';
 UPDATE coasters SET coaster_description = coasterDesc WHERE coaster_id = '12345'; 
END;

Leave a comment