<connectionString> problems

S

Simon

Hello,

I am trying to add the additional connection string. I have added this to
Web.config file:

<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>

And than I also included:

connStr =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;

And this fails, because ConnStr is not found. If I check all available
connection strings I only get LocalSqlServer.

What am I doing wrong? Is there something that I have to run to update the
connection strings?

Best regards

Simon
 
S

Steffen Hoppe

Hello Simon,

where is your <connectionStrings> Section located in the web.config? It must
be a child of <configuration>. Your code looks fine to me.

If this does not help, please post your web.config.

Cheers,
Steffen
 
J

Juan T. Llibre

re:
!> <add name="ConnStr" connectionString="XXX" />

You are missing the providerName property in your new connection string.

<configuration>
<connectionStrings>
<clear/>
<add name="LocalSqlServer" connectionString="XXX" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
 
M

Mark Moeykens

I think Steffen is on to something. It could be your web.config that's the
problem. I was able to access the connection string just fine. Let me paste
in my entire web.config so you can compare it's structure against yours. I
deleted all the xml that wasn't needed to get the solution to work:
---------------------------------------------------------------
web.config
---------------------------------------------------------------
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
</configuration>
---------------------------------------------------------------
I didn't need to specify the ProviderName like Juan suggested to make it work.

Here's my code in my code behind:
---------------------------------------------------------------
default.aspx.cs
---------------------------------------------------------------
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblConnString.Text =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
}
}
---------------------------------------------------------------

Hope this helps,
Mark Moeykens


Steffen Hoppe said:
Hello Simon,

where is your <connectionStrings> Section located in the web.config? It must
be a child of <configuration>. Your code looks fine to me.

If this does not help, please post your web.config.

Cheers,
Steffen
Hello,

I am trying to add the additional connection string. I have added this
to Web.config file:

<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
And than I also included:

connStr =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;

And this fails, because ConnStr is not found. If I check all available
connection strings I only get LocalSqlServer.

What am I doing wrong? Is there something that I have to run to update
the connection strings?

Best regards

Simon
 
J

Juan T. Llibre

re:
!> I didn't need to specify the ProviderName like Juan suggested to make it work.
!>lblConnString.Text = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;

What you did was display the text in a label.
That works whether the providerName property is included...or not.

If you actually tried to make that connection retrieve data,
it would not...unless you included the providerName property.





Mark Moeykens said:
I think Steffen is on to something. It could be your web.config that's the
problem. I was able to access the connection string just fine. Let me paste
in my entire web.config so you can compare it's structure against yours. I
deleted all the xml that wasn't needed to get the solution to work:
---------------------------------------------------------------
web.config
---------------------------------------------------------------
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
</configuration>
---------------------------------------------------------------
I didn't need to specify the ProviderName like Juan suggested to make it work.

Here's my code in my code behind:
---------------------------------------------------------------
default.aspx.cs
---------------------------------------------------------------
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblConnString.Text =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
}
}
---------------------------------------------------------------

Hope this helps,
Mark Moeykens


Steffen Hoppe said:
Hello Simon,

where is your <connectionStrings> Section located in the web.config? It must
be a child of <configuration>. Your code looks fine to me.

If this does not help, please post your web.config.

Cheers,
Steffen
Hello,

I am trying to add the additional connection string. I have added this
to Web.config file:

<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
And than I also included:

connStr =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;

And this fails, because ConnStr is not found. If I check all available
connection strings I only get LocalSqlServer.

What am I doing wrong? Is there something that I have to run to update
the connection strings?

Best regards

Simon
 
S

Steffen Hoppe

Hello Juan,

I am a bit surprised, as the connection strings in my application are working
without the "providername" property. I access them as described by Simon.
Is this some "default" setting to "System.Data.SqlClient", as I am accessing
an MSSQL2k8?

Cheers,
Steffen

mailto:[email protected]
re:
!> I didn't need to specify the ProviderName like Juan suggested to
make it work.
!>lblConnString.Text =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
What you did was display the text in a label.
That works whether the providerName property is included...or not.
If you actually tried to make that connection retrieve data, it would
not...unless you included the providerName property.


message
I think Steffen is on to something. It could be your web.config
that's the
problem. I was able to access the connection string just fine. Let
me paste
in my entire web.config so you can compare it's structure against
yours. I
deleted all the xml that wasn't needed to get the solution to work:
---------------------------------------------------------------
web.config
---------------------------------------------------------------
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
</configuration>
---------------------------------------------------------------
I didn't need to specify the ProviderName like Juan suggested to make
it work.
Here's my code in my code behind:
---------------------------------------------------------------
default.aspx.cs
---------------------------------------------------------------
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblConnString.Text =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
}
}
---------------------------------------------------------------
Hope this helps,
Mark Moeykens
Steffen Hoppe said:
Hello Simon,

where is your <connectionStrings> Section located in the web.config?
It must be a child of <configuration>. Your code looks fine to me.

If this does not help, please post your web.config.

Cheers,
Steffen
Hello,

I am trying to add the additional connection string. I have added
this to Web.config file:

<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
And than I also included:
connStr =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
And this fails, because ConnStr is not found. If I check all
available connection strings I only get LocalSqlServer.

What am I doing wrong? Is there something that I have to run to
update the connection strings?

Best regards

Simon
 
J

Juan T. Llibre

re:
!> I am a bit surprised, as the connection strings in my application
!> are working without the "providername" property.

No need to be surprised, since System.Data.SqlClient is the default provider.

Not everybody uses System.Data.SqlClient, though.
We can't assume that you're developing with SQL Server.

Many developers implement their own providers, and they
won't be able to connect unless they specify the providerName.

Also, if you develop with Oracle, OleDb or Odbc,
you'll need to specify the appropiate providerName.






Steffen Hoppe said:
Hello Juan,

I am a bit surprised, as the connection strings in my application are working without the "providername" property. I
access them as described by Simon. Is this some "default" setting to "System.Data.SqlClient", as I am accessing an
MSSQL2k8?

Cheers,
Steffen

mailto:[email protected]
re:
!> I didn't need to specify the ProviderName like Juan suggested to
make it work.
!>lblConnString.Text =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
What you did was display the text in a label.
That works whether the providerName property is included...or not.
If you actually tried to make that connection retrieve data, it would
not...unless you included the providerName property.


message
I think Steffen is on to something. It could be your web.config
that's the
problem. I was able to access the connection string just fine. Let
me paste
in my entire web.config so you can compare it's structure against
yours. I
deleted all the xml that wasn't needed to get the solution to work:
---------------------------------------------------------------
web.config
---------------------------------------------------------------
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
</configuration>
---------------------------------------------------------------
I didn't need to specify the ProviderName like Juan suggested to make
it work.
Here's my code in my code behind:
---------------------------------------------------------------
default.aspx.cs
---------------------------------------------------------------
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblConnString.Text =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
}
}
---------------------------------------------------------------
Hope this helps,
Mark Moeykens
:

Hello Simon,

where is your <connectionStrings> Section located in the web.config?
It must be a child of <configuration>. Your code looks fine to me.

If this does not help, please post your web.config.

Cheers,
Steffen
Hello,

I am trying to add the additional connection string. I have added
this to Web.config file:

<connectionStrings>
<clear/>
<add name="ConnStr" connectionString="XXX" />
</connectionStrings>
And than I also included:
connStr =
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
And this fails, because ConnStr is not found. If I check all
available connection strings I only get LocalSqlServer.

What am I doing wrong? Is there something that I have to run to
update the connection strings?

Best regards

Simon
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top