共用方式為


SqlConnectionStringBuilder.ApplicationName 屬性

定義

取得或設定與連接字串相關聯的應用程式名稱。

public:
 property System::String ^ ApplicationName { System::String ^ get(); void set(System::String ^ value); };
public string ApplicationName { get; set; }
member this.ApplicationName : string with get, set
Public Property ApplicationName As String

屬性值

應用程式的名稱,如果沒有提供任何名稱,則為 ".NET SqlClient Data Provider"。

例外狀況

若要將值設定為 null,請使用 Value

範例

下列範例會建立新的 SqlConnectionStringBuilder,並在物件的建構函式中指派連接字串。 此程式碼會顯示已剖析及重建的連接字串版本,然後修改此物件的 ApplicationName 屬性。 最後,此程式碼會顯示新的連接字串,包括新的索引鍵/值組。

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        try
        {
            string connectString = "Server=(local);Initial Catalog=AdventureWorks;" +
                "Integrated Security=true";
            SqlConnectionStringBuilder builder =
                new SqlConnectionStringBuilder(connectString);
            Console.WriteLine("Original: " + builder.ConnectionString);
            Console.WriteLine("ApplicationName={0}",
                builder.ApplicationName);

            builder.ApplicationName = "My Application";
            Console.WriteLine("Modified: " + builder.ConnectionString);

            Console.WriteLine("Press any key to finish.");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}
Imports System.Data.SqlClient

Module Module1

    Sub Main()
        Try
            Dim connectString As String = _
             "Server=(local);Initial Catalog=AdventureWorks;" & _
                 "Integrated Security=True"
            Dim builder As New SqlConnectionStringBuilder(connectString)
            Console.WriteLine("Original: " & builder.ConnectionString)
            Console.WriteLine("ApplicationName={0}", _
                builder.ApplicationName)
            builder.ApplicationName = "My Application"
            Console.WriteLine("Modified: " & builder.ConnectionString)

            Console.WriteLine("Press any key to finish.")
            Console.ReadLine()

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Module

此範例會在主控台視窗中顯示以下文字:

Original: Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True
ApplicationName=".Net SqlClient Data Provider"
Modified: Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True;Application Name="My Application"

備註

此屬性會對應至連接字串內的 "Application Name" 和 "app" 索引鍵。

適用於

另請參閱