views:

144

answers:

1

I have got a class library project and a winforms app.

Everything is getting geerated fine and my Winforms app references the class library but as soon as I run it and try to retreive data it comes up with dataprovider is null.

The one thing to note is that I do not have a app.config in my Winforms app only in the class library. Do I need one in the Winforms app and if so what do I put in it?

Thanks

UPDATE: I think I have found a bug in Query\Select.cs

    public Select(IDataProvider provider, params string[] columns)
    {
        //_provider is null
        //provider is populated correctly
        this.sqlFragment = new SqlFragment(_provider);
        _provider = provider;
        SelectColumnList = columns;
        SQLCommand = this.sqlFragment.SELECT;
    }
+1  A: 

Yes, you need an App.config in your Winforms app and you put your connection string there. It's worth noting that an App.config is pointless in a class library EXCEPT when you're using SubSonic :), which will pull one from the project.

Class libraries don't have their own configuration - they pull their config from the execution environment.

Rob Conery
I have put a app.config in my class library along with the TT files and all seems to work. I think what might have been the problem is the bug in Subonsic. If you look at my update _provider needs to be assigned before calling a new SqlFragment
Jon
The templates grap the connectionstring and other subsonic related stuff from the app.config off the class library during design time. At runtime the connectionstrings have to be in the main (in this case winform app) project. So you have to maintain your config twice.
SchlaWiener
I have no config in my winforms app and all is ok. I just think there is a bug in subsonic. The lines of source I posted, the 1st two need swapping I think
Jon
How is my app working without a app.config in the winforms app and only in the class library project?
Jon
I don't know. I do know you're the only one to report this - I have to assume it's in your setup.
Rob Conery
I just double checked and there is definately no app.config or connection string stuff in my winforms project. That references the class library project which has the connection string and all TT templates etc in it
Jon