﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Accessing BOs from a Console App.</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 07 Apr 2026 15:39:07 GMT</lastBuildDate><ttl>20</ttl><item><title>Accessing BOs from a Console App.</title><link>http://forum.strataframe.net/FindPost30305.aspx</link><description>&lt;font color="#000000" face="Times New Roman"&gt;&lt;font size="3"&gt;We have developed a StrataFrame application and have created and tested some code that does file moves and table updates.&amp;nbsp; 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.&amp;nbsp; 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. &lt;br/&gt;&lt;/font&gt;&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;&lt;font color="#000000" face="Times New Roman"&gt;&lt;font size="3"&gt;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?&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;/font&gt;&lt;/font&gt;</description><pubDate>Tue, 06 Sep 2011 12:11:53 GMT</pubDate><dc:creator>Charles Blake</dc:creator></item><item><title>RE: Accessing BOs from a Console App.</title><link>http://forum.strataframe.net/FindPost30311.aspx</link><description>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.</description><pubDate>Tue, 06 Sep 2011 12:11:53 GMT</pubDate><dc:creator>Charles Blake</dc:creator></item><item><title>RE: Accessing BOs from a Console App.</title><link>http://forum.strataframe.net/FindPost30310.aspx</link><description>It is if you haven't set the DataSourceKey property to another value on the BO itself.&amp;nbsp; 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.&lt;br/&gt;&lt;br/&gt;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.&amp;nbsp; Finally, are you just running this at the moment through a console app or as an actual service? </description><pubDate>Tue, 06 Sep 2011 10:40:05 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Accessing BOs from a Console App.</title><link>http://forum.strataframe.net/FindPost30309.aspx</link><description>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.&lt;br/&gt;&lt;br/&gt;DataBasics.DataSources.Add(new SqlDataSourceItem("", "Server=localhost;Integrated Security=SSPI;Initial Catalog=MyDatabase;"));&lt;br/&gt;&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br/&gt;APP_BO.tbl_test boTest;&lt;br/&gt;boTest = new APP_BO.tbl_test();&lt;br/&gt;decimal initialSize = boTest.Get_Size();</description><pubDate>Tue, 06 Sep 2011 10:18:48 GMT</pubDate><dc:creator>Charles Blake</dc:creator></item><item><title>RE: Accessing BOs from a Console App.</title><link>http://forum.strataframe.net/FindPost30308.aspx</link><description>This can definitely be done.&amp;nbsp; So most likely you are not defining your data sources (connections) before the first time that the BO attempts to access the DAL.&amp;nbsp; Before you ever create an instance of the BO, be sure that you data source is created.&amp;nbsp; In a standard WinForms app, this is done in the SetDataSources method of the Appmain.vb or program.cs files.&amp;nbsp; So you will need to do this manually yourself.&amp;nbsp; I generally do this first thing at the top of the Main when creating console apps.&amp;nbsp; We use a lot of console apps and services for maintenance or "tasked" operations. &lt;br/&gt;&lt;br/&gt;Also, make sure that your DataSourceKey that is defined in your BO has a matching Datasource that has been created.&lt;br/&gt;&lt;br/&gt;&lt;span&gt;[codesnippet]MicroFour.StrataFrame.Data.DataBasics.DataSources.Add(new SqlDataSourceItem("", "Connection String Here"));[/codesnippet]&lt;/span&gt;</description><pubDate>Tue, 06 Sep 2011 10:00:45 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Accessing BOs from a Console App.</title><link>http://forum.strataframe.net/FindPost30307.aspx</link><description>&lt;font size="3"&gt;Well I guess the issue I am running into is initialization.&amp;nbsp; As soon as I access a BO I get the following error:&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;&lt;font size="3"&gt;&lt;br/&gt;&lt;/font&gt;&lt;font size="3"&gt;“An error occurred while creating a new DataLayer for the business object.”&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;font size="3"&gt;I have included a reference to my BO and do see a copy in the debug folder.&amp;nbsp; I also supplied a data source prior to the access as follows:&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;font size="3"&gt;DataLayer.DataSources.Add(new SqlDataSourceItem("", "Server=localhost;Integrated Security=SSPI;Initial Catalog=MyDatabase;"));&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;font size="3"&gt;Is there other initialization code required to access the BO?&lt;br/&gt;&lt;/font&gt;</description><pubDate>Tue, 06 Sep 2011 09:52:00 GMT</pubDate><dc:creator>Charles Blake</dc:creator></item><item><title>RE: Accessing BOs from a Console App.</title><link>http://forum.strataframe.net/FindPost30306.aspx</link><description>Hi Charles,&lt;br/&gt;[quote][b]Charles Blake (9/6/2011)[/b][hr]&lt;font color="#000000" face="Times New Roman"&gt;&lt;font size="3"&gt;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?&lt;/font&gt;&lt;/font&gt;[/quote]&lt;br/&gt;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.&lt;br/&gt;The SF Business dll will give you all the access you need to work with your data from any .Net project application.</description><pubDate>Tue, 06 Sep 2011 08:59:11 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item></channel></rss>