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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:51:29+00:00 2026-06-02T16:51:29+00:00

I have some existing WCF code that accesses SQL Server 2005, but honestly I’ve

  • 0

I have some existing WCF code that accesses SQL Server 2005, but honestly I’ve come to mistrust that developer’s methods, so I want to know how this should be done correctly and professionally. I need to be able to pass an SQL statement to a method (within the WCF service, not from the client) that returns the resultant dataset (to the method in WCF that called it, not the client). I’m not interested in entity frameworks or other abstraction layers. I need to run SQL, DML, and hopefully DDL too.

I also want to know how to manage the connections.

Please point out your thoughts on better alternatives if you feel like it. I’m prepared to listen.

  • 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-06-02T16:51:30+00:00Added an answer on June 2, 2026 at 4:51 pm
    • Save your connection string in the configuration file.
    • Connect to the Database as much as you like, Connection Pool will take care of that you do not have to worry about it.
    • Always use using when dealing with sql connections.

      Using (sqlConn = new SqlConnection(ConnString)) { }

    • Make your own POCOs to return the result to the client, you can either make them in seperate assembly and share it in both projects (WCF and client) or you can just add them to the WCF and when you create the proxy at the client side you will have access to them.

    Here is a sample layout:

    public Poco Foo(long id)
    {
        try
        {
            using (SqlConnection SqlConn = new SqlConnection(ConnString))
            {
                // execute your commands and do your stuff
                return Poco;
            }
        }
        catch (Exception ex)
        {
            Logger.Log(ex.ToString());
            return null;
        }
    }
    

    UPDATE

    Here is an example of how to return a ‘DataSet` to the client, I do not recommend this but it will work:

    public DataSet Foo(long id)
        {
            try
            {
                using (SqlConnection SqlConn = new SqlConnection(ConnString))
                {
                    SqlCommand sqlCmd = new SqlCommand("Select * From users where userid=@id", SqlConn);
                    sqlCmd.Parameters.Add("@id", SqlDbType.BigInt).Value = id;
                    DataSet ds = new DataSet();
                    using (SqlDataAdapter da = new SqlDataAdapter(sqlCmd))
                    {
                        da.Fill(ds, "Users");
                    }
    
                    return ds;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString);
                return null;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some existing code that worked fine under Windows 2003, to obtain the
I have some existing code that retrieves data from a database using ADO.NET that
I have some existing C code that uses ICMP raw sockets to do Ping
I have some existing code that uses an enum instead of a function pointer
I have some existing code which isn't formatted consistently -- sometimes two spaces are
I have some existing custom Excel workbooks/applications with code-behind C#, which work fine. They
I have to analyse some existing Erlang code. Does anybody knows about a tool
Some existing web services I consume have methods that look something like this: List<Employee>
I have problem to add jQuery to some existing code, please help. We have
I have an existing database that has some testing data into and I'm interested

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.