Data connection

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
10/3/2008 3:03:09 AM
Gravatar
Total Posts 69

Data connection

Hi, I can't figure out connection strings in Visual Studio

I'm running VS 2008 and SQL Express. I've set the correct string in web.config and the site runs fine on my local machine. I've also added a custom table to the database to hold the data I need.

I then added a datagrid to my new module page but to do that VS asks for a data source so I tell it where the data is. now when I test the module in a browser I get an error telling me that the connection string (for the grid's data source) can't be found.

Am I missing something obvious here? Can't VS pick up the original connection string from web.config?

10/3/2008 6:54:32 AM
Gravatar
Total Posts 18439

Re: Data connection

In mojoPortal we use the connection string from the appSettings section of Web.config and DataGrids or DataSourceControls don't know about this connection string. You would probably need to add a ConnectionStrings section and add a named connection string for it to find it.

In mojoPortal we use a 3 layer model where the UI code talks to a business object to get its data and the business object talks to the data service layer. For professional quality features I recommend you follow this same pattern and look at how grids are populated in existing features. MS makes it easy for you to not follow best practices by creating things like SqlDataSourceControl that connects the UI directly to the database. I mean its ok for quick and dirty projects I suppose, but using Codesmith templates I can usually put something together just as quick that does follow best practices so hooking up data directly in the UI makes me feel dirty ;-). Still if you are happy with that approach nothing stops you from doing it.

Hope it helps,

Joe

10/7/2008 12:58:21 PM
Gravatar
Total Posts 8

Re: Data connection

Here is a snippet of code I have used on my site that certain modules were converted from VB.net to C# to work with Mojoportal

User.config <add key="JobsConnection" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Jobs.mdf;Integrated Security=True;User Instance=True" />
 

 ASCX or Aspx page for MojoPortal

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ Appsettings:JobsConnection %>"
 

The key is using the Appsettings: instead of Connectionstring:

bb

You must sign in to post in the forums. This thread is closed to new posts.