StrataFrame Forum

Retrieving connection string without using ConnectionManager

http://forum.strataframe.net/Topic13649.aspx

By Doug Birtell - 1/22/2008

A little background...

1) I am using click once deployment, and I do not want the user to see the database setup wizard.

2) because of #1, I have to use DataLayer.DataSources.Add to add my database connection

3) The main application (Program.cs) runs many other SF forms.

4) Some of these SF forms read data directly (do not use BO's)

so far so good?

Question: How can I create s SQLConnection and pass it the ConnectString without using ConnectionManager to get it?

i.e.how can I get the connection string from the datalayer? I really don't want to code the connectstring in all of my forms that need it when not using the BO to get the data.

I know this is probably so obvious it's stupid, but....

Thanks in advance.

Doug

By Bill Cunnien - 1/22/2008

Doug Birtell (01/22/2008)

Question: How can I create s SQLConnection and pass it the ConnectString without using ConnectionManager to get it?

Hi Doug,

Here is what I did.  I commented out everything in the ConnectionManger section, then I created each data source manually.  Like this:

DataLayer.DataSources.Add(new SqlDataSourceItem("MyDB", "Data Source=DBSERVER;Initial Catalog=MyReallyCoolDB;User ID=sa;Password=pwd;Asynchronous Processing=True")); 

I have one of these entries for every connection that I may use in the application.  This is the only place that they show up.  I also have each BO's DataSourceKey pointing to one of these data sources (DataSourceKey=MyDB).  Depending on which primary BO is used on a given form the form will utilize that connection string.  Of course, you could do more work to grab these strings from an external source (e.g. encrypted file), but I have left them right in my program.cs file.  All has worked quite well, so far.

Hope that helps,
Bill

By Doug Birtell - 1/22/2008

Bill,

I understand what you are saying, and that is exactly what I have done.  The problem is that I have a menu form that calls multiple SF Maintenance forms as well as SF standard forms that run reports.  These "report" forms do not make use of the BO's, thus, I need to use SQLCommand to retrieve data based on how a form is filled out.  I have not figured out how to create the SQLCommand object, which needs the SQLConnect string, which is in the program.cs. (without using the ConnectionManager) I did not want to duplicate the connect string in all of the report forms.  Does that all make sense?

Thanks!

Doug

By Bill Cunnien - 1/22/2008

Sure.  That makes sense.  After re-reading the initial post, I can see where I misunderstood you.  Sorry about that.

Try this:

MicroFour.StrataFrame.Data.DataLayer.DataSources["MyDB"].ConnectionString;

Hope that helps,
Bill

By Trent L. Taylor - 1/22/2008

That's it, Bill..good answer.  Also, Doug, I thought I would mention that you can use a BusinessBindingSOurce as the data source fora  report.  This is how we do our reports within our medical software.  In fact, I am hoping to release a sample that shows how to use Report-Shooter with a BBS. 
By Doug Birtell - 1/23/2008

Bill ! ! !

That's exactly what I was looking for.  Worked perfectly. 

Trent,

I'll look forward to seeing your example on using the BBS in reporting.  Maybe I'm just too used to doing things the old fashioned way

Thanks for all the help!

Doug