Accessing BOs from a Console App.


Author
Message
Charles Blake
Charles Blake
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 88
We have developed a StrataFrame application and have created and tested some code that does file moves and table updates.  At this point it makes more sense to move some of these methods to a console application that can be called from a cron type service to be run at specific intervals.  Since these classes don’t use forms or invoke message boxes it would appear that we could easily port this code to a console application.


My question is can I access and use my StrataFrame BOs from the console application; most of the startup code that I see is for Win Forms?



Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Charles,
Charles Blake (9/6/2011)
My question is can I access and use my StrataFrame BOs from the console application; most of the startup code that I see is for Win Forms?

Sure you can, or if this is part of some automated process you can build a Windows Service and a Front End GUI form to configure the settings like connection string, etc.
The SF Business dll will give you all the access you need to work with your data from any .Net project application.

Edhy Rijo

Charles Blake
Charles Blake
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 88
Well I guess the issue I am running into is initialization.  As soon as I access a BO I get the following error:


“An error occurred while creating a new DataLayer for the business object.”


I have included a reference to my BO and do see a copy in the debug folder.  I also supplied a data source prior to the access as follows:


DataLayer.DataSources.Add(new SqlDataSourceItem("", "Server=localhost;Integrated Security=SSPI;Initial Catalog=MyDatabase;"));


Is there other initialization code required to access the BO?

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
This can definitely be done.  So most likely you are not defining your data sources (connections) before the first time that the BO attempts to access the DAL.  Before you ever create an instance of the BO, be sure that you data source is created.  In a standard WinForms app, this is done in the SetDataSources method of the Appmain.vb or program.cs files.  So you will need to do this manually yourself.  I generally do this first thing at the top of the Main when creating console apps.  We use a lot of console apps and services for maintenance or "tasked" operations.

Also, make sure that your DataSourceKey that is defined in your BO has a matching Datasource that has been created.

MicroFour.StrataFrame.Data.DataBasics.DataSources.Add(new SqlDataSourceItem("", "Connection String Here"));

Charles Blake
Charles Blake
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 88
If the following is all I need than I will re-validate the datasource, although I have used that datasource to access the table directly.

DataBasics.DataSources.Add(new SqlDataSourceItem("", "Server=localhost;Integrated Security=SSPI;Initial Catalog=MyDatabase;"));

           
APP_BO.tbl_test boTest;
boTest = new APP_BO.tbl_test();
decimal initialSize = boTest.Get_Size();
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
It is if you haven't set the DataSourceKey property to another value on the BO itself.  The DataSourceKey on the BO allows you to have as many different connections as you need and then tell the BO which connection to use through the DataSourceKey.

Also, if this doesn't work, I would like to see the full stack-trace so we can see at what point the error is occurring.  Finally, are you just running this at the moment through a console app or as an actual service?
Charles Blake
Charles Blake
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 88
Thanks, I was able to get connected by using the ConnectionManager and supplying it with the same keys and data we use in the application.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search