Dailycode.info

Short solution for short problems

unable to load the specified metadata resource. on the entity framework

I was settings up a new project that would use the entity framework as data layer. something I've done a lot the last years. This time the only difference was the client being a WFP client. Settings up the project identical as before, I couldn't get the the entity framework working properly. I keep gettings the error when I call the entity framework: unable to load the specified metadata resource. After searching for a while  and trying almost everythin I could find. Changing the entity connection string over and over. Creating a new solution etc, it stil didn't work. totday I was looking more into the assembly part. for some reason the resources where not available in the assemblies on the client. 

THE SOLUTION:

The reason the resources are not found had nothing to do with the Connection string. I tried almost everything possible. The reason was because the dll where the edmx file was in was not yet loaded into memory. Because I was using the linked classes, it appears that is didn't load the dll hence the resources. I solved this by just calling a void function that did nothing:

 public void test()

 {}

This function is located in the same dll as the edmx. Next if you call the context it works!!!. I looked on the internet a lot, but did not find this solution. I hope this can save people time.


Global Variables using the Singleton Pattern (IOS)

As a .Net developer, I'm used to work with the Singleton pattern. This can come in very handy, also for caching purposes. Although it can be dangerous to just put in large amount of data on the client. Keeping this in mind, I created a Global Variables Store as a Singleton to store the apps global settings. I started by creating an objective C class. called it: VariableStore. The header of the class looks like this:

//

//  VariableStore.h

//  GALVASFIAPP01

//

//  Created by Mark Deraeve on 25/09/12.

//  Copyright (c) 2012 __Galvapower__. All rights reserved.

//

 

#import <UIKit/UIKit.h>

 

@interface VariableStore : NSObject

 

{

    NSString *MESuploadPath;

    NSString *MESwebservicesPath;

    NSString *MESPlant;

    NSString *MESWorkPlace;

    

}

 

+ (VariableStore *) sharedInstance;

 

@property (nonatomic, retain) NSString *MESUploadPath;

@property (nonatomic, retain) NSString *MESwebservicesPath;

@property (nonatomic, retain) NSString *MESPlant;

@property (nonatomic, retain) NSString *MESWorkPlace;

 

@end

 

Then the implementation file looks like this:

 

//

//  VariableStore.m

//  GALVASFIAPP01

//

//  Created by Mark Deraeve on 25/09/12.

//  Copyright (c) 2012 __Galvapower__. All rights reserved.

//

 

#import "VariableStore.h"

 

@implementation VariableStore

 

@synthesize MESPlant=_MESPlant;

@synthesize MESUploadPath=_MESUploadPath;

@synthesize MESWorkPlace=_MESWorkPlace;

@synthesize MESwebservicesPath=_MESwebservicePath;

 

+ (VariableStore *) sharedInstance

{

    static VariableStore *myInstance = nil;

    

    if (nil == myInstance)

    {

        myInstance = [[[self class] alloc] init];

        myInstance.MESUploadPath =@"http://server/FileUpload/upload.php";

    }

    return myInstance;

}

 

 

@end

 

 

Now you can use these variables anywhere in your application if you import the VariableStore header file. You can do this like following:

#import "VariableStore.h"

...

[[VariableStoresharedInstance] setMESUploadPath:@"http://server/FileUpload/upload.php"];

or to get a value:

NSString *urlString = [[VariableStoresharedInstance] MESUploadPath];


MPMoviePlayerPlaybackDidFinishNotification results in a black screen

I had a hard time implementing the MPMoviePlayer. After a lot of search and some tutorials, I got what I wanted. But just one last thing was ginning me trouble. The user presses a button in the application to show the movie. Its shown in full screen mode, after the movie is finished the user should come back in the first screen. Here's the code on how I show the video (at the end I add the event DidFinish of the movie player to the notification center.):

 

- (IBAction)btnPlayVideo:(id)sender 
{
    MPMoviePlayerController *mov = [[MPMoviePlayerController allocinitWithContentURL:self.videoUrl];

    

    [mov prepareToPlay];
    mov.view.frame = self.view.bounds;
    mov.scalingMode = MPMovieScalingModeAspectFit;
    mov.movieSourceType = MPMovieSourceTypeFile;
    mov.controlStyle = MPMovieControlStyleDefault;
    self.moviePlayer = mov;
    [self.view addSubview:self.moviePlayer.view];
 
    self.moviePlayer.initialPlaybackTime = 0,0;
    [self.moviePlayer setFullscreen:YES animated:YES];
    [self.moviePlayer prepareToPlay];
    [self.moviePlayer play];

    

    [[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer ];
 
}

 

The problem was that when the movie is finished, I get a black screen and nothing is possible anymore in the application. The app is completely blocked. So I searched some and first somebody suggested to stop the movie before removing the player from the super view. But that didn't work. then another suggested to set the control style to none before removing it. Still nothing happened, but the last try was close to the solution I found there after. I had to set the control style to embedded before removing it. Here the code that worked for me at the end:

- (void) moviePlayBackComplete:(NSNotification *)notification

{

    MPMoviePlayerController *moviePlayer = [notification object];

    [[NSNotificationCenterdefaultCenter] removeObserver:selfname:MPMoviePlayerPlaybackDidFinishNotificationobject: moviePlayer];

   

    [moviePlayer setFullscreen: NO animatedYES];   

 

    [moviePlayer stop ];

    [moviePlayer setControlStyle:MPMovieControlStyleEmbedded];

    [moviePlayer.view removeFromSuperview];

}

 

It only worked every time after I added the line: setFullscreen: NO animated: YES. So the 


vba ADO stored procedure in recordset 'Operation is not allowed when the object is closed'

I was trying to open a recordset from a stored procedure. I had the hardest time gettings this to work.

When me and my collegue Koen looked for solutions, Koen Goyens found this solution that worked: Add NextRecordset before you use the recordset, because the first recordset will always be empty. Here's a function that will return the recordset when you give a parameter and the name of the stored procedure:

 

' ------------------------------------------------------------------------------------------
' ---   Function opens a recordset using a Stored Procedure passed as parameter (sSQL)    ---
' ------------------------------------------------------------------------------------------
  Public Function OpenADOStoredProcedureRecordset(ByVal sSQL As String) As ADODB.Recordset

    Dim tmpConn As ADODB.Connection
    Dim RS As New ADODB.Recordset
    Dim cmd As ADODB.Command

    On Error GoTo RecordsetError

    ' --- Get the active connection (it will be opened if it's closed) ---------------------
    Set tmpConn = ADOConnection
    LogInfo "Started Stored Procedure: " & sSQL
    Set RS = New ADODB.Recordset ' --- create new ADO recordset struct. & get data ------
    RS.Open sSQL, tmpConn, adOpenUnspecified, adLockUnspecified

    Set OpenADOStoredProcedureRecordset = RS.NextRecordset
        
    LogInfo "End Stored Procedure: " & sSQL

    Exit Function

RecordsetError:
    AdoStatus = False
    AdoErr = Err.Number
    AdoErrDescr = Err.Description
    LogError "Error in OpenADOStoredProcedureRecordset: " & Err.Description
    Set RS = Nothing
    Set cmd = Nothing

  End Function

 The parameter sSql looks like this: exec spoMyStoredProc '0145698725658'

So when I call this function I get my result in the recordset and can start looping over it.