Использование псевдонима SQL в ConnectionStringC#

Место общения программистов C#
Anonymous
Использование псевдонима SQL в ConnectionString

Сообщение Anonymous »

Я установил локальный псевдоним для экземпляра sql.
sqldev -> myserver/MSSQLSERVERDEV
Мне интересно, возможно ли это использовать этот псевдоним в строке подключения. (пример ниже).

Код: Выделить всё

    static void Main(string[] args)
{
OpenSqlConnection();
Console.Read();
}

private static void OpenSqlConnection()
{
try
{
string connectionString = GetConnectionString();

using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = connectionString;

connection.Open();

Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}",
connection.ConnectionString);
}
}catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

}

static private string GetConnectionString()
{
return "Data Source=sqldev;Initial Catalog=Data;"
+ "Integrated Security=true;";
}
Я могу подключиться к серверу, используя псевдоним в SSMS, и подключиться к C#, используя полное имя экземпляра, но когда я подключаюсь к C#, используя псевдоним, я получаю следующую ошибку.

Код: Выделить всё

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Возможно ли использование псевдонима в строке соединения SQL, и если да, то что я делаю не так?

Подробнее здесь: https://stackoverflow.com/questions/791 ... tionstring

Вернуться в «C#»