String used to create a connection string to TestDB - ADO.NET

Q.  You are a Web developer for CareerRide. The data is stored in a Microsoft SQL Server 2005 database on a server named CareerPC and the Database name is TestDB. You connect to TestDB by using Windows Integrated authentication. You use a SqlConnection object to connect to the database. You need to create a connection string to TestDB in the instance of SQL Server named CareerPC. Which string should you use?

- Published on 28 Jul 15

a. “Data Source= CareerPC; Database=TestDB; Integrated Security=SSP1”.
b. “Data Source= CareerPC; Initial Catalog=TestDB; Integrated Security=SSP1”.
c. “Server= CareerPC; Database=TestDB; Integrated Security=SSP1”.
d. All of the above.

ANSWER: All of the above.
 

    Discussion

  • Raj   -Posted on 19 Oct 15
    You can write Data Source or Server or Address or Addr or Network Address to the instance of SQL Server to which to connect. These all are same, you can write any one of these. To specify the database you should either use the Database or the Initial Catalog attribute.

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)