C# user defined function: Is there a way to access the name of the sql server?

This is my problem: I do not know how to get the servername from a C# user defined function . Is this possible

I am writing a User Defined Function (UDF). Inside of this user defined function I need the name of the databaseserver that it is running on. Does anyone have an idea how I might do this Is there an enviromental variable that I could access within the C# code I use to write the UDF

I could always use a parameter to pass in the name of the server, but I would like to have as few parameters as possible.

Thanks in advance,

Sean



Answer this question

C# user defined function: Is there a way to access the name of the sql server?

  • StefanH07

    Use the context connection and do:
     
    SELECT @@SERVERNAME
     

    --
    Adam Machanic
    Pro SQL Server 2005, available now
    http://www..apress.com/book/bookDisplay.html bID=457
    --
     
     
    This post has been edited either by the author or a moderator in the Microsoft Forums: http://forums.microsoft.com

    This is my problem: I do not know how to get the servername from a C# user defined function . Is this possible

    I am writing a User Defined Function (UDF). Inside of this user defined function I need the name of the databaseserver that it is running on. Does anyone have an idea how I might do this Is there an enviromental variable that I could access within the C# code I use to write the UDF

    I could always use a parameter to pass in the name of the server, but I would like to have as few parameters as possible.

    Thanks in advance,

    Sean


  • Solanice

    Or without issueing a command,you could use just:

    SqlConnection conn = new SqlConnection("context connection=true");
    conn.Open();
    // conn.Database --> hold the string of the database name
    conn.Close();

    HTH, Jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---


  • C# user defined function: Is there a way to access the name of the sql server?