307645 PRB: Cannot be connected to SQL Server (from MKBA) on any port other than 1433

xiaoxiao2021-03-06  72

The release number of this article has been CHS307645

This article references the following Microsoft .NET Framework Class Bank Name Space:

System.data.sqlclient

SYMPTOMS When you use a protocol other than the Transmission Control Protocol / Internet Protocol (TCP / IP), if you specify a port other than 1433 to connect to an instance of Microsoft SQL Server,

SqlConnection.Open will fail.

Solution To resolve this issue, use the TCP / IP protocol and enable the connection string including "Server = ComputerName, PortNumber".

More information

Steps to reproduce the phenomenon

Start Microsoft Visual Studio .NET. Newly built a Visual C # .NET console application project. Make sure your project contains a reference to System.Data namespace, if not included, add a reference to this namespace. Using the USING statement for System, System.Data, and System.Data.sqlclient namespace, this is not required to qualify the declarations in these namespaces in the later code. Using system;

Using system.data;

Using system.data.sqlclclient; Visual Studio will create a static class and an empty main process by default. Copy the following code, then paste it into the code window: Class Class1

{

Static void main (string [] args)

{

String sconnectionstring;

Sconnectionstring = "User ID = sa; initial catalog = pubs; data source = myserver, 1200";

SqlConnection Objconn = New SqlConnection; SconnectionsTRING

Objconn.open ();

Sqldataadapter Daauthors = New SqldataAdapter ("Select * from authors", objconn);

DataSet DSPUBS = New Dataset ("Pubs");

Daauthors.Fillschema (DSPUBS, Schematype.Source, "Authors");

Daauthors.Fill (DSPUBS, "Authors");

Daauthors.MissingSchemaAction = missingschemaAction.addwithkey;

Daauthors.Fill (DSPUBS, "Authors");

DataTable tblauthors;

TBLAUTHORS = DSPUBS.TABLES ["authors"];

Foreach (Datarow Drcurrent In TBLAUTHORS.ROWS)

{

Console.writeLine ("{0} {1}",

Drcurrent ["au_fname"]. TOSTRING (),

Drcurrent ["au_lname"]. TOSTRING ());

}

Console.readline ();

}

} Modify the Sconnectionstring string according to your environment. Save the project. Start with the debug menu, and run your project to connect to the database.

The information in this article applies to:

Microsoft ADO.NET (provided with .NET Framework) Microsoft Visual C # .NET (2002) Received: 2002-6-17 (1.0) Keyword KBDsupport KBGRPDSMDAC KBGRPDSVBDB KBPRB KBSQLCLIENT KBSYSTEMDATA KB307645

转载请注明原文地址:https://www.9cbs.com/read-108933.html

New Post(0)