Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 372237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:11:29+00:00 2026-05-12T14:11:29+00:00

am using MVC and Subsonic 3.0.0.3 but i cant seem to pin down a

  • 0

am using MVC and Subsonic 3.0.0.3 but i cant seem to pin down a specific point for multiple database connection.

normally in normal .net i would have my 2 strings in the web.config file
and have a database class for my project, within this db class i would do something like this:

try
        {
            conn.ConnectionString = server1;
            conn.Open();
        }
        catch (MySqlException)
        {
            conn.ConnectionString = server2;
            conn.Open();
        }

I am trying to pin down the one place in subsonic’s created files where something like this would be best to place and maybe an up to date example on how to achieve it. I have googled etc but the examples shown are for an older subsonic.

many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:11:29+00:00Added an answer on May 12, 2026 at 2:11 pm

    If you look in Context.tt at line 35 you’ll see the following code:

    public <#=DatabaseName#>DB() 
    { 
        DataProvider = ProviderFactory.GetProvider("<#=ConnectionStringName#>");
        Init();
    }
    

    This is where the provider is getting setup for you so if you add a BackupConnectionStringName variable in Settings.ttinclude after the ConnectionStringName at line 20 then you should be able to check your connection is working and user your fallback if not. For example:

    public <#=DatabaseName#>DB() 
    { 
        DataProvider = ProviderFactory.GetProvider("<#=ConnectionStringName#>");
        Init();
        try
        {
            DataProvider.CreateConnection();
        }
        catch(SqlException)
        {
           DataProvider = ProviderFactory.GetProvider("<#=BackupConnectionStringName#>");
           Init(); 
        }
    }
    

    NB You may need to do some clean up to make sure a connection is not left open by CreateConnection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using subsonic to access my DB in a mvc application. When trying
I have a relatively simple ASP.net MVC 2 app that is using SubSonic. Everything
I´m using mvc futures 2 with WebApiEnabled for XML and JSON support. But due
I'm using ASP.NET MVC (1.0), Spark View Engine (1.0) and SubSonic (3.0.0.3). I'm having
I'm interested in using Subsonic 3.0 for developing a new ASP.Net MVC application that
I am using MVC 3. The page contents come from SQL database. I notice
I am using the Subsonic MVC Template and in the List.tt template it loops
I am new to Subsonic3. Want to create a project using MVC and subsonic
I am developing MVC 3 application and its first time i am using subsonic.
Using MVC and trying to use dependency injection for controllers, but when I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.