Microsoft KB Archive/307645

= You cannot connect to SQL Server on any port other than 1433 if you use a protocol other than TCP/IP =

Article ID: 307645

Article Last Modified on 3/29/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft ADO.NET 2.0
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# 2005

-



This article was previously published under Q307645



This article refers to the following Microsoft .NET Framework Class Library namespace:
 * System.Data.SqlClient



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



RESOLUTION
To resolve this problem, use TCP/IP protocol, and include &quot;Server=ComputerName, PortNumber&quot; in the connection string.



Steps to reproduce the behavior
 Start Microsoft Visual Studio .NET. Create a new Visual C# .NET Console Application project. Make sure that your project contains a reference to the System.Data namespace, and add a reference to this namespace if it does not.  Use the using statement on the System, System.Data, System.Data.SqlClient namespaces so that you are not required to qualify declarations in those namespaces later in your code. using System; using System.Data; using System.Data.SqlClient;   Visual Studio creates a static class and an empty Main procedure by default. Copy the following code, and paste it in the Code window:

Note You must change the User ID value and the password value to the correct values before you run this code. Make sure that User ID has the appropriate permissions to perform this operation on the database. class Class1 {    static void Main(string[] args) {        string sConnectionString; sConnectionString = &quot;User ID= ;Password = ;Initial Catalog=pubs;Data Source=myServer,1200&quot;; SqlConnection objConn = new SqlConnection(sConnectionString); objConn.Open; SqlDataAdapter daAuthors = new SqlDataAdapter(&quot;Select * From Authors&quot;, objConn);

DataSet dsPubs = new DataSet(&quot;Pubs&quot;); daAuthors.FillSchema(dsPubs, SchemaType.Source, &quot;Authors&quot;); daAuthors.Fill(dsPubs, &quot;Authors&quot;); daAuthors.MissingSchemaAction = MissingSchemaAction.AddWithKey; daAuthors.Fill(dsPubs, &quot;Authors&quot;);

DataTable tblAuthors; tblAuthors = dsPubs.Tables[&quot;Authors&quot;]; foreach (DataRow drCurrent in tblAuthors.Rows) {            Console.WriteLine(&quot;{0} {1}&quot;,              drCurrent[&quot;au_fname&quot;].ToString,              drCurrent[&quot;au_lname&quot;].ToString); }        Console.ReadLine; } }                    Modify the sConnectionString string as appropriate for your environment.</li> Save your project.</li> On the Debug menu, click Start, and run your project to connect to the database.</li></ol>

Keywords: kbnofix kbprb kbsqlclient kbsystemdata KB307645

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.