Default SQLExpress connectionString

G

Guest

In 2.0 when I access the ConnectionStringSettingsCollecion using the integer
index rather than declaratively using the key of the configuration element I
get a SQLExpress connection string which I haven't defined myself at the
reference zero. E.g.

string s = ConfigurationManager.ConnectionStrings[0].ConnectionString;

After running this s evaluates to

{data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true}

Of course the connection string at location 1 is the first specified stirng
in the config file.

Whats this all about then? I can't find any mention of this in the docs, or
anybody talking about it, and I can't find anyway to stop it. I had a quick
nose in reflector but didn't find anything useful quickly.

Anybody else come across this and can explain why its there at all and how
to get rid of it.

Cheers

Rob
 
W

W.G. Ryan - MVP

Rob - there are already default connection strings in the collection. That's
one of them. All you need to do is clear the defaults in the collection
like this - call <clear/> right after you open the connectionStrings
element:

<connectionStrings>

<clear/>

<add name="AdventureWorksString" providerName="System.Data.SqlClient"

connectionString="Data Source=localhost;Initial Catalog=AdventureWorks;
Integrated Security=true"/> </connectionStrings>
 
C

Cor Ligthert [MVP]

Rob,

Did you start your program with a sample as template. It looks much like
that.

Just as idea

Cor
 
G

Guest

Ah ok fair enough, so this is an inherited setting from machine.config I
guess as clear removes inherited settings and that would also explain why
nothing came out of reflector. Having a daft day I guess...

It wasn't so much how to get rid I was interested in really as thats easy to
workaround though thanks for the tip as it is clearer *groan* that way.

Its the why have a default connection string and why not really obviously
document it that i wonder. Whats it there for? What use it to me? Is it to
support something in the framework (one of the auto-magical asp.net 2.0
features like membership perhaps)?

Rob



W.G. Ryan - MVP said:
Rob - there are already default connection strings in the collection. That's
one of them. All you need to do is clear the defaults in the collection
like this - call <clear/> right after you open the connectionStrings
element:

<connectionStrings>

<clear/>

<add name="AdventureWorksString" providerName="System.Data.SqlClient"

connectionString="Data Source=localhost;Initial Catalog=AdventureWorks;
Integrated Security=true"/> </connectionStrings>

Rob Williams said:
In 2.0 when I access the ConnectionStringSettingsCollecion using the
integer
index rather than declaratively using the key of the configuration element
I
get a SQLExpress connection string which I haven't defined myself at the
reference zero. E.g.

string s = ConfigurationManager.ConnectionStrings[0].ConnectionString;

After running this s evaluates to

{data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true}

Of course the connection string at location 1 is the first specified
stirng
in the config file.

Whats this all about then? I can't find any mention of this in the docs,
or
anybody talking about it, and I can't find anyway to stop it. I had a
quick
nose in reflector but didn't find anything useful quickly.

Anybody else come across this and can explain why its there at all and how
to get rid of it.

Cheers

Rob
 
G

Guest

Its a C# Windows Forms Project, Cor, created in VS 2005. Is that what you
mean by template? The settings are in the app.config file I added myself.

Rob

Cor Ligthert said:
Rob,

Did you start your program with a sample as template. It looks much like
that.

Just as idea

Cor

Rob Williams said:
In 2.0 when I access the ConnectionStringSettingsCollecion using the
integer
index rather than declaratively using the key of the configuration element
I
get a SQLExpress connection string which I haven't defined myself at the
reference zero. E.g.

string s = ConfigurationManager.ConnectionStrings[0].ConnectionString;

After running this s evaluates to

{data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true}

Of course the connection string at location 1 is the first specified
stirng
in the config file.

Whats this all about then? I can't find any mention of this in the docs,
or
anybody talking about it, and I can't find anyway to stop it. I had a
quick
nose in reflector but didn't find anything useful quickly.

Anybody else come across this and can explain why its there at all and how
to get rid of it.

Cheers

Rob
 
W

W.G. Ryan - MVP

You're right, it's there b/c of Machine.config - that's why calling clear is
considered the 'safe' way to handle it b/c otherwise, you may not know what
else could be loaded outside of your application.

The existing value is there for support purposes, and I forget what feature
it's there for, but yes, it's ASP.NET related - I think it's there for
Membership but I don't remember for sure off the top of my head.
Rob Williams said:
Ah ok fair enough, so this is an inherited setting from machine.config I
guess as clear removes inherited settings and that would also explain why
nothing came out of reflector. Having a daft day I guess...

It wasn't so much how to get rid I was interested in really as thats easy
to
workaround though thanks for the tip as it is clearer *groan* that way.

Its the why have a default connection string and why not really obviously
document it that i wonder. Whats it there for? What use it to me? Is it to
support something in the framework (one of the auto-magical asp.net 2.0
features like membership perhaps)?

Rob



W.G. Ryan - MVP said:
Rob - there are already default connection strings in the collection.
That's
one of them. All you need to do is clear the defaults in the collection
like this - call <clear/> right after you open the connectionStrings
element:

<connectionStrings>

<clear/>

<add name="AdventureWorksString" providerName="System.Data.SqlClient"

connectionString="Data Source=localhost;Initial Catalog=AdventureWorks;
Integrated Security=true"/> </connectionStrings>

Rob Williams said:
In 2.0 when I access the ConnectionStringSettingsCollecion using the
integer
index rather than declaratively using the key of the configuration
element
I
get a SQLExpress connection string which I haven't defined myself at
the
reference zero. E.g.

string s = ConfigurationManager.ConnectionStrings[0].ConnectionString;

After running this s evaluates to

{data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true}

Of course the connection string at location 1 is the first specified
stirng
in the config file.

Whats this all about then? I can't find any mention of this in the
docs,
or
anybody talking about it, and I can't find anyway to stop it. I had a
quick
nose in reflector but didn't find anything useful quickly.

Anybody else come across this and can explain why its there at all and
how
to get rid of it.

Cheers

Rob
 

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