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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:16:31+00:00 2026-05-31T10:16:31+00:00

Would it be wise to Use a Dll to access a database When a

  • 0

Would it be wise to Use a Dll to access a database When a application starts.

This is the code i have to call in every page in my app

  SqlConnection myConnection = new SqlConnection();
    myConnection.ConnectionString = "Data Source=CRYSTAL5\\INSTANCE1;Initial Catalog=Pharmacy;Integrated Security=True";
    myConnection.Open(); 

and the dll code i wrote

public  class DBConnect
    {
        public DBConnect()
        {
            Initialize();
        }
        private SqlConnection connection;
        //Constructor


    //Initialize values
    private void Initialize()
    {
        string connectionString;
        connectionString = "Data Source=CRYSTAL5\\INSTANCE1;Initial Catalog=Pharmacy;Integrated Security=True";

        connection = new SqlConnection(connectionString);
    }

i then added using DBCon; in my app and tried to run this code

DBConnect myConnection = new DBConnect();
        SqlCommand myCommand = new SqlCommand("select doc_fname,doc_lname,gender,department,education ,NMC_no  from ph.doctor_info where unit_id =0", myConnection);

it won’t work.

sorry for the crappy description

The best overloaded method match for ‘System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)’ has some invalid arguments
is the error i get

What would i do without stack overflow.

  • 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-31T10:16:33+00:00Added an answer on May 31, 2026 at 10:16 am

    You are passing an object of type “DbConnect” to SqlCommand rather than an SqlConnection object. Your sql connection object is held within this class, in the connection variable.

    You will either need to make this field public, or alternatively create a function which returns the data connection.

    If making connection public, you would then do:

    SqlCommand myCommand = new SqlCommand("select doc_fname,doc_lname,gender,department,education ,NMC_no  from ph.doctor_info where unit_id =0", myConnection.connection);
    

    EDIT: Also in Initialise, you have created the SqlConnection object, but not called Open(). You will need to do this before trying to use the connection. Either add connection.Open() to initialise(), or call myConnection.connection.Open() prior to calling the SqlCommand.

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

Sidebar

Related Questions

So I have this application that would have multiple modules, from project management to
Would setting the $link to my database be one thing that I should use
I have a Java desktop application I wrote, and I would like a recommendation
I am building a dynamic partial load asp.net page, I would like to use
It seems that it would be wise to use def, fn, or fun for
I have a product image class. This is an object with re-use potential for
What would be the most optimal algorithm (performance-wise) to calculate the number of divisors
Would the following SQL remove also the index - or does it have to
Would having a nice little feature that makes it quicker to write code like
I've encountered a problem drawing SFML Text. In my application, I use views as

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.