Results 1 to 3 of 3

Thread: Single database & multiple functions in web services.

  1. #1
    Join Date
    Jan 2009
    Posts
    44

    Single database & multiple functions in web services.

    Hi,

    In Web Method I want to share the database among the functions using SQL connection & ODBC connection along with the using structure. Now some functions need to update the database already accessed & opened by the web method.
    Now the problem is when the database is open the functions cant see the database & if i want the functions to connect to the database then do I need to create new connection for the same database? IS this possible?

  2. #2
    Join Date
    Jan 2009
    Posts
    22

    Re: Single database & multiple functions in web services.

    Well do you know the ADO.net feature from VB.Net?
    With Adaptor it establishes connection with the database & creates a virtual image of the database & all the queries are executed on it and as soon as the connection is closed all the changes are saved to the actual database.
    Now this is what you need. where it is possible.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Single database & multiple functions in web services.

    As for "using", you can also use a "try...catch...finally" block to replace
    it. For example:

    ===================
    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Dim conn As SqlConnection = Nothing
    
    Try
    conn = New
    SqlConnection(ConfigurationManager.ConnectionStrings("myConnectionString").C
    onnectionString)
    
    '......
    
    Catch ex As Exception
    
    Finally
    
    conn.Close()
    End Try
    
    End Sub
    ==================

    the "finally" block will help ensure the connection get closed even there
    occurs exception(the same as using).

    Also, here I use "ConfigurationManager.ConnectionStrings" collection to
    retrieve connectionstring info(instead of hard code it in each function).
    And the actual connecction string is defined in app.config as below:

    =-====================
    Code:
    <?xml version='1.0' encoding='utf-8'?>
    <configuration>
    <connectionStrings>
    <clear />
    <add name="myConnectionString"
    connectionString="[Connection String content here]" />
    </connectionStrings>
    ..........................
    </configuration>
    =====================

    #Connection Strings and Configuration Files (ADO.NET)
    http://msdn.microsoft.com/en-us/library/ms254494.aspx

    #Getting connection string from app.config in .NET 2.0
    http://shico.blogspot.com/2007/04/g...tring-from.html

    In addition, if you want to further centralize your code so as to avoid
    duplicated connection creating code, you can encapsulate them in a utility
    class. e.g.

    ==============
    Code:
    public class DBUtil
    
    Public Shared Function GetConnection(ByVal connName As String) As
    SqlConnection
    
    Dim conn As New
    SqlConnection(ConfigurationManager.ConnectionStrings(connName).ConnectionStr
    ing)
    
    Return conn
    
    End Function
    
    end class
    =============

    Then, you can call this utility function in each place you need to create
    connection.

Similar Threads

  1. Multiple IPs in single domain
    By Mettalica in forum Networking & Security
    Replies: 4
    Last Post: 14-11-2010, 02:47 AM
  2. pipelined functions in oracle 9i database
    By Norse in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 10:04 PM
  3. Start and Stop Services in a single batch file?
    By Dilbert in forum Windows Software
    Replies: 4
    Last Post: 20-01-2010, 09:29 PM
  4. Add a multiple movies in a single DVD
    By BUCK in forum Windows Software
    Replies: 3
    Last Post: 15-05-2009, 10:53 AM
  5. Simple C# calculator that functions from single text box
    By Connect_Me in forum Software Development
    Replies: 4
    Last Post: 26-01-2009, 06:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,054,642.80099 seconds with 17 queries