Archive for category Error

Templates can be used only with field access… error using ToShortDateString()

While binding a partial view to a model, I noticed the my nullable DateTime field was showing the time portion. Adding attributes to the model didn’t work, so I attempted to use the ToShortDateString() method:

@Html.TextBoxFor(model => Model.StartDate.Value.ToShortDateString(), new { @class = “form-control”, @maxlength = “10” })

However, this caused the error “Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions”.

To get around this, set the shortened date value to a string, and used that as the binding to the textbox:

var startDate = Model.StartDate.Value.ToShortDateString();

@Html.TextBoxFor(model => startDate, new { @class = “form-control”, @maxlength = “10” })

Advertisements

Leave a comment

Unable to find the requested .Net Framework Data Provider. It may not be installed.

While moving a web application to a new web server, an application which used Entity Framework returned this message when loading:

ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.

   System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +959971

   System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +26

 

And this message also appeared a bit lower on the yellow screen of death:

ArgumentException: The specified store provider cannot be found in the configuration, or is not valid.

 

The problem was with the DbProviderFactories elements in the machine.config file – it didn’t have the correct drivers installed. To fix it, I opened Notepad (Visual Studio wasn’t installed on the server) as an administrator because the file wouldn’t let me save it otherwise. I scrolled down the <system.data> section, which initially looked like this:

<system.data>

<DbProviderFactories />

</system.data>

 

I replaced it with the section below which I pulled from my local machine. I have left in all the libraries in case that helps, though in our environment, we didn’t use the SQL Server CE drivers:

<system.data>

             <DbProviderFactories>

<add name=”ODP.NET, Managed Driver” invariant=”Oracle.ManagedDataAccess.Client” description=”Oracle Data Provider for .NET, Managed Driver” type=”Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342″/>

<add name=”ODP.NET, Unmanaged Driver” invariant=”Oracle.DataAccess.Client” description=”Oracle Data Provider for .NET, Unmanaged Driver” type=”Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342″/>

<add name=”Microsoft SQL Server Compact Data Provider 4.0″ invariant=”System.Data.SqlServerCe.4.0″ description=”.NET Framework Data Provider for Microsoft SQL Server Compact” type=”System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91″/>

<add name=”Microsoft SQL Server Compact Data Provider” invariant=”System.Data.SqlServerCe.3.5″ description=”.NET Framework Data Provider for Microsoft SQL Server Compact” type=”System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91″/>

               </DbProviderFactories>

</system.data>

Leave a comment

ORA-00918: column ambiguously defined with CASE column

I had an Oracle query that was returning the error “ORA-00918: column ambiguously defined” when I tried to run it:

SELECT * FROM ( 
  SELECT ID, CASE
    WHEN something THEN something else
    ELSE yet more
  END CASE
FROM ScottsTable
UNION ALL
  SELECT ID, CASE 
    WHEN something THEN something else
    ELSE yet more
  END CASE
FROM ScottsTableHistory
) ORDER BY 1 ASC, 2;

The problem was originating in the first query’s CASE statement. I needed to put an alias on the first CASE statement to avoid the naming duplication that was causing Oracle to hate me. Here is the final, modified query:

SELECT * FROM ( 
  SELECT ID, CASE
    WHEN something THEN something else
    ELSE yet more
  END "MY COLUMN"
FROM ScottsTable
UNION ALL
    SELECT ID, CASE 
    WHEN something THEN something else
  ELSE yet more
END CASE
FROM ScottsTableHistory
) ORDER BY 1 ASC, 2;

Leave a comment

HTTP Error 403.14 for MVC site

I was setting up a new MVC 5 site on a Windows Server 2016 Datacenter machine when I ran into this error:

HTTP Error 403.14 – Forbidden – The Web server is configured to not list the contents of this directory.

I didn’t actually want the web server to list the contents, so that was not the problems.

This fancy Internet thing had lots of suggestions, the best ones at Stack Overflow. However, those didn’t solve my problem. What did solve my problem was to correct a dumb mistake. Here was my IIS configuration:

IIS

 

 

 

You’ll notice the ever-populate “ScottSite” is looking like a sad, plain folder. And that was my problem – I hadn’t turned it into an application. Right-clicking on my non-application and selecting “Convert to application” fixed my problem. Magic.

IIS

 

 

 

Leave a comment

Type or namespace name could not be found when building in Release mode

When building a web application with Visual Studio in Debug mode, I wasn’t getting any errors. But when I switched to Release mode, I received this error:

The type or namespace name ‘ScottStuff’ could not be found (are you missing a using directive or an assembly reference?)

There was no conditional logic to exclude that ScottStuff library based on the configuration I was using.

The problem was that when I made the reference to the ScottStuff DLL, I had included it from a different directory, c:\SomeDirectory\ScottStuff.dll. To fix the issue, I instead referenced the DLL from the bin folder of the project I was working on, c:\Projects\ScottProject\bin\ScottStuff.dll. After doing this, the project compiled successfully.

Leave a comment

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;'

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