Problems with my SQL Server connection string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SAL

    Problems with my SQL Server connection string

    Hello,

    I am working with Framework 1.1 and Microsoft Enterprise Library 2005. I've
    used the Enterprise Library Configuration utility to create my app.config &
    dataConfigurati on.config files.

    My question is, why is the Enterprise Library stripping out my User Id and
    Password from my SQL Server connection string, that I have in the
    dataConfigurati on file? This is an internal app that has no UI and is an
    automated process that runs Store procedures which is why I have the UID and
    PWD in my dataConfigurati on file. When the Enterprise Library reads the
    dataConfigurati on.config file it passes the following connection string to
    SQL Server:

    data source=sql123;i nitial catalog=MyDb;pe rsist security info=true;packe t
    size=4096
    Instead of this one:
    data source=SQL123;i nitial catalog=MyDb;pe rsist security info=False;user
    id=youruid;;pac ket size=4096; password=yourpw d"

    Is following C# code I have missing a step that is causing my issue:

    Database db = DatabaseFactory .CreateDatabase ("SQL Server");

    string sqlCommand = "autoApInput_ge tFile";
    DBCommandWrappe r dbCommandWrappe r =
    db.GetStoredPro cCommandWrapper (sqlCommand);

    // Add paramters
    // Input parameters can specify the input value
    dbCommandWrappe r.AddInParamete r("@visitor", DbType.Int32, 1);
    dbCommandWrappe r.AddInParamete r("@po", DbType.String, "0018487402 ");
    dbCommandWrappe r.AddInParamete r("@poAmount" , DbType.String, "$156.25");

    db.ExecuteNonQu ery(dbCommandWr apper);

    And the following is the ConnectionStrin g block I have in my
    dataConfigurati on.config file:

    <connectionStri ng name="SQL Connection String">
    <parameters>
    <parameter name="data source" value="SQL123" isSensitive="fa lse"/>
    <parameter name="initial catalog" value="MyDB"
    isSensitive="fa lse" />
    <parameter name="persist security info" value="False"
    isSensitive="fa lse" />
    <parameter name="uid" value="userid" isSensitive="tr ue" />
    <parameter name="packet size" value="4096" isSensitive="fa lse" />
    <parameter name="pwd" value="password " isSensitive="tr ue" />
    </parameters>
    </connectionStrin g>

    Thanks,
  • Chris Dunaway

    #2
    Re: Problems with my SQL Server connection string

    SAL wrote:
    >
    data source=sql123;i nitial catalog=MyDb;pe rsist security info=true;packe t
    size=4096
    Instead of this one:
    data source=SQL123;i nitial catalog=MyDb;pe rsist security info=False;user
    id=youruid;;pac ket size=4096; password=yourpw d"
    >
    >
    And the following is the ConnectionStrin g block I have in my
    dataConfigurati on.config file:
    >
    <connectionStri ng name="SQL Connection String">
    <parameters>
    <parameter name="data source" value="SQL123" isSensitive="fa lse"/>
    <parameter name="initial catalog" value="MyDB"
    isSensitive="fa lse" />
    <parameter name="persist security info" value="False"
    isSensitive="fa lse" />
    <parameter name="uid" value="userid" isSensitive="tr ue" />
    <parameter name="packet size" value="4096" isSensitive="fa lse" />
    <parameter name="pwd" value="password " isSensitive="tr ue" />
    </parameters>
    </connectionStrin g>
    >
    IIRC, the parameter names need to be named the same as they will appear
    in the connection string.

    I think the problem is caused by the naming you use for the user id and
    password parameters. Instead of uid, try User Id and instead of pwd,
    try Password.

    Here is the configuration we use:

    <connectionStri ng name="BeddingTe st">
    <parameters>
    <parameter name="database" value="database "
    isSensitive="fa lse" />
    <parameter name="Password" value="password "
    isSensitive="tr ue" />
    <parameter name="server" value="server" isSensitive="fa lse"
    />
    <parameter name="User Id" value="user" isSensitive="fa lse" />
    </parameters>
    </connectionStrin g>

    Comment

    • SAL

      #3
      Re: Problems with my SQL Server connection string

      Hi Chris,

      Thanks. You were partially correct, however it wasn't in the parameter name
      but in the value itself. They changed my Initial Catalog value to include an
      underscore (_) in the value and I wasn't aware of it. Why, I have no clue.
      As soon as I changed it, it worked like a charm.

      Thanks again for your help.

      "Chris Dunaway" wrote:
      SAL wrote:

      data source=sql123;i nitial catalog=MyDb;pe rsist security info=true;packe t
      size=4096
      Instead of this one:
      data source=SQL123;i nitial catalog=MyDb;pe rsist security info=False;user
      id=youruid;;pac ket size=4096; password=yourpw d"


      And the following is the ConnectionStrin g block I have in my
      dataConfigurati on.config file:

      <connectionStri ng name="SQL Connection String">
      <parameters>
      <parameter name="data source" value="SQL123" isSensitive="fa lse"/>
      <parameter name="initial catalog" value="MyDB"
      isSensitive="fa lse" />
      <parameter name="persist security info" value="False"
      isSensitive="fa lse" />
      <parameter name="uid" value="userid" isSensitive="tr ue" />
      <parameter name="packet size" value="4096" isSensitive="fa lse" />
      <parameter name="pwd" value="password " isSensitive="tr ue" />
      </parameters>
      </connectionStrin g>
      >
      IIRC, the parameter names need to be named the same as they will appear
      in the connection string.
      >
      I think the problem is caused by the naming you use for the user id and
      password parameters. Instead of uid, try User Id and instead of pwd,
      try Password.
      >
      Here is the configuration we use:
      >
      <connectionStri ng name="BeddingTe st">
      <parameters>
      <parameter name="database" value="database "
      isSensitive="fa lse" />
      <parameter name="Password" value="password "
      isSensitive="tr ue" />
      <parameter name="server" value="server" isSensitive="fa lse"
      />
      <parameter name="User Id" value="user" isSensitive="fa lse" />
      </parameters>
      </connectionStrin g>
      >
      >

      Comment

      Working...