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 931147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:27:16+00:00 2026-05-15T20:27:16+00:00

I have a whole slew of database access functions which assume a particular connection

  • 0

I have a whole slew of database access functions which assume a particular connection string. Within my application I call

myList = DB_MyTable.GetTableItems()

and within GetTableItems() I have something like

Dim connection As SqlConnection = MyDB.GetConnection

So the connection string is in one place in the code, and I call a method to get it.

What I’m running into now is I want to reuse the same database functions, but with a different connection string. I can rewrite all of the functions like DB_MyTable.GetTableItems() easily because they’re generated from a script, but within the main application code I’ll need to take care of every function call that now needs to know what connection string I want to use.

I tried changing the arguments to GetTableItems() like this:

Public Shared Function GetTableItems(Optional ByVal useThisString as String = MyDB.GetConnection) As List(Of MyItems)

in hopes of being able to pass in, by default, the string I’m already using in most of the code, but I got an error saying that the default value had to be a constant expression. This would mean peppering a specific connection string everywhere, which I don’t want to do.

Is there a way to accomplish what I’m after, or do I need to make the connection string a required argument and change all of the calls in my application to match the new signature?

Thanks as always!

  • 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-15T20:27:17+00:00Added an answer on May 15, 2026 at 8:27 pm

    Can you make your default value an empty string? Then, in your functions, if the useThisString variable is blank, then use default, else use the one you passed in? A littler dirtier, but just barely.

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

Sidebar

Related Questions

I have a whole XML document in a String which i need to convert
We have a whole bunch of DLLs that give us access to our database
We have a whole catalogue of videos which we would like to stream to
I have a whole bunch of projects which I want to reuse between the
i have downloaded whole database from geonames.org and imported all countries into mysql. i
I have a whole list of entity classes which I need to make Serializable
So I have a whole pre-existing directory, let's call it c:/src/foo , with a
I have whole page HTML in my database and i want write that html
I have a whole bunch of dates in three columns which are used by
I have a whole bunch of string that are supposed to represent MIME types.

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.