Dela via


SqlConnection.WorkstationId Property

Definition

Gets a string that identifies the database client.

public:
 property System::String ^ WorkstationId { System::String ^ get(); };
public string WorkstationId { get; }
member this.WorkstationId : string
Public ReadOnly Property WorkstationId As String

Property Value

A string that identifies the database client. If not specified, the name of the client computer. If neither is specified, the value is an empty string.

Examples

The following example creates a SqlConnection and displays the WorkstationId property.

using Microsoft.Data.SqlClient;

class Program
{
    static void Main()
    {
        string s = GetConnectionString();

        OpenSqlConnection(s);
        Console.ReadLine();
    }

    private static void OpenSqlConnection(string connectionString)
    {
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            connection.Open();
            Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
            Console.WriteLine("WorkstationId: {0}", connection.WorkstationId);
        }
    }

    static private string GetConnectionString()
    {
        // To avoid storing the connection string in your code, 
        // you can retrieve it from a configuration file, using the 
        // System.Configuration.ConfigurationSettings.AppSettings property 
        return "Data Source=(local);Initial Catalog=AdventureWorks;"
            + "Integrated Security=SSPI;";
    }
}

Remarks

The string typically contains the network name of the client. The WorkstationId property corresponds to the Workstation ID connection string property.

Applies to