简体   繁体   中英

SqlConnectionStringBuilder - String was not recognized as a valid Boolean

I am attempting to pass in a connection string to an SqlConnectionStringBuilder object, but I get the error: "String was not recognized as a valid Boolean", at runtime.

Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace SQLClientProj
{
  class Program
  {
    static void Main(string[] args)
    {
      string cstr = @"Data Source=(local)\SQLEXPRESS;Integrated Security=IIPS;Initial Catalog=Autos";

      SqlConnectionStringBuilder cbuilder = new SqlConnectionStringBuilder(cstr);

      ...

As far as I know, cstr is a string, so why SqlConnectionStringBuilder is complaining about expecting a boolean when it doesn't have a constructor which accepts such a type is beyond my understanding.

Any ideas?

Integrated Security=IIPS 

needs to be

Integrated Security=true

'IIPS' is not a boolean (true/false)

In a nutshell, the connection string is made up of property-value pairs,and the "Integrated Security" property specified in your string is expected to be true or false.

Look down at the "Integrated Security" section on this page:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx

The token you are looking for is SSPI , not IIPS [sic]. Then, of course, you could, as others said, simply use true (or false ).

Just a hunch, but should

Integrated Security=IIPS

be

Integrated Security=True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM