Problems with my SQL Server connection string

G

Guest

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 &
dataConfiguration.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
dataConfiguration 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 dataConfiguration file. When the Enterprise Library reads the
dataConfiguration.config file it passes the following connection string to
SQL Server:

data source=sql123;initial catalog=MyDb;persist security info=true;packet
size=4096
Instead of this one:
data source=SQL123;initial catalog=MyDb;persist security info=False;user
id=youruid;;packet size=4096; password=yourpwd"

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

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

string sqlCommand = "autoApInput_getFile";
DBCommandWrapper dbCommandWrapper =
db.GetStoredProcCommandWrapper(sqlCommand);

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

db.ExecuteNonQuery(dbCommandWrapper);

And the following is the ConnectionString block I have in my
dataConfiguration.config file:

<connectionString name="SQL Connection String">
<parameters>
<parameter name="data source" value="SQL123" isSensitive="false"/>
<parameter name="initial catalog" value="MyDB"
isSensitive="false" />
<parameter name="persist security info" value="False"
isSensitive="false" />
<parameter name="uid" value="userid" isSensitive="true" />
<parameter name="packet size" value="4096" isSensitive="false" />
<parameter name="pwd" value="password" isSensitive="true" />
</parameters>
</connectionString>

Thanks,
 
C

Chris Dunaway

SAL said:
data source=sql123;initial catalog=MyDb;persist security info=true;packet
size=4096
Instead of this one:
data source=SQL123;initial catalog=MyDb;persist security info=False;user
id=youruid;;packet size=4096; password=yourpwd"


And the following is the ConnectionString block I have in my
dataConfiguration.config file:

<connectionString name="SQL Connection String">
<parameters>
<parameter name="data source" value="SQL123" isSensitive="false"/>
<parameter name="initial catalog" value="MyDB"
isSensitive="false" />
<parameter name="persist security info" value="False"
isSensitive="false" />
<parameter name="uid" value="userid" isSensitive="true" />
<parameter name="packet size" value="4096" isSensitive="false" />
<parameter name="pwd" value="password" isSensitive="true" />
</parameters>
</connectionString>

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:

<connectionString name="BeddingTest">
<parameters>
<parameter name="database" value="database"
isSensitive="false" />
<parameter name="Password" value="password"
isSensitive="true" />
<parameter name="server" value="server" isSensitive="false"
/>
<parameter name="User Id" value="user" isSensitive="false" />
</parameters>
</connectionString>
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top