I have a very complex data structure within a web application that im working on, which requires 3 connections at once to a MSSQL database, id rather not but its the only way to achieve what is required for now.
I set my connectionstrings in web.config as such:
<connectionStrings>
<add name="Foo_mainConnectionString1" connectionString="Data Source=GDE-WK-003\SQLEXPRESS;Initial Catalog=Foo_main;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="Foo_mainConnectionString2" connectionString="Data Source=GDE-WK-003\SQLEXPRESS;Initial Catalog=Foo_main;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="Foo_mainConnectionString3" connectionString="Data Source=GDE-WK-003\SQLEXPRESS;Initial Catalog=Another_FOO;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
When set up as above (2 connections to the same DB) it works fine (although the third ' Another_FOO' is an unused one from a discontinued part of the project.
So in order to get another connection established, i changed "Another_FOO" to "Foo_Main"
Giving me 3 connections to the same DB.
On trying to run the website, it now seems that none of the connections are established.
Any ideas why this might be? Is there likely to be a connection limit that i cant find?
Related
How to write the connection string to local SQL Server database using web.config?
Here is my connection string in web.config. But when I open local/demo, it said:
login failed for user ''.
Actually I'm using Windows authentication, so I thought it doesn't need user and password.
<connectionStrings>
<add name="HRISContext"
connectionString="data source=.;initial catalog=BPSDEMO;Pooling=false;persist security info=True;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
If you want to use Windows authentication, then yes, you must not include any user id and pwd in your connection string - just remove those completely. But you must include the Integrated Security=SSPI setting instead.
Try this:
<connectionStrings>
<add name="HRISContext"
connectionString="data source=.;initial catalog=BPSDEMO;Integrated Security=SSPI;MultipleActiveResultSets=True;Pooling=false;persist security info=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
I installed Sql Server Express but I need to use localhost as Datasource in connection string.
Here is the connection string now:
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS.../>
I want to use like this:
<add name="DefaultConnection" connectionString="Data Source=localhost
Is there a way to use localhost alias instead of ".\sqlexpress" in connection string. I work in a team project and the other people use connection string like that (they have installed sql server - not express)
You have to mention only localhost and database name like below
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=DatabaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
I am deploying an ASP.NET web app to Azure Web Sites.
The site uses Entity Framework, and when I include the following in Web.config it runs fine:
<connectionStrings>
<add name="DataContext" connectionString="metadata=res://*/Models.WpsData.csdl|res://*/Models.WpsData.ssdl|res://*/Models.WpsData.msl;provider=System.Data.SqlClient;provider connection string="data source=XXXX;initial catalog=XXXX;persist security info=True;user id=XXXX;password=XXXX;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
However, if this connection string is removed and instead specified via the Azure Management Portal, an error occurs.
Name: DataContext
Value: metadata=res://*/Models.WpsData.csdl|res://*/Models.WpsData.ssdl|res://*/Models.WpsData.msl;provider=System.Data.SqlClient;provider connection string="data source=XXXX;initial catalog=XXXX;persist security info=True;user id=XXXX;password=XXXX;multipleactiveresultsets=True;application name=EntityFramework"
Type: Custom
This results in the error: No connection string named 'DataContext' could be found in the application config file.
See similar question here.
Try leaving the connection string in web.config with some value (either some test connection string, or some dummy value) e.g.
<connectionStrings>
<add name="DataContext" connectionString="dummy" providerName="System.Data.EntityClient" />
</connectionStrings>
I'm using SQL Session State in my app, however given that we have several connection strings already, it would be easier to maintain the config if all the connection strings were held, well, in <connectionStrings>.
My question is, is it possible somehow to specify an existing connection string in the sessionState config?
<connectionStrings>
<add name="ConnString1" connectionString="data source=xx;Initial Catalog=zzz;"
providerName="System.Data.SqlClient" />
<add name="EFConnString"
connectionString="metadata=res://*/EF.csdl|res://*/EF.ssdl|res://*/EF.msl;provider=System.Data.SqlClient;provider connection string="data source=xxx;initial catalog=yyy;App=EntityFramework""
providerName="System.Data.EntityClient" />
<add name="SessionStateConn" connectionString="data source=xx;Initial Catalog=zzz;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<sessionState mode="SQLServer"
sqlConnectionString="**SessionStateConn**"
sqlCommandTimeout="30" customProvider="" ... etc
</sessionState>
Anyone coming to this late the MSDN documentations state that for the sqlConnectionString attribute you can specify either the full connection string OR the name of an existing connection string:
https://msdn.microsoft.com/en-us/library/h6bb9cz9%28v=vs.85%29.aspx
(see sqlConnectionString under Attributes & Elements)
Not really. At least not in a straightforward way that does not require change in the code or transforming the configuration file. The reason behind this inconsistency in ASP.NET is that SQL Server session state was introduced in the original version of ASP.NET whereas the connectionStrings section was added in version 2.0. The sessionState tag designers could not rely on a system that had not been invented/shipped yet.
i have connection string stored in web.config file but it is giving me the error.
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbProduct.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
where is the bug in the connection string. i have stored my db DbProduct.mdf in app_data folder. i have never use SQLEXPRESS. so i need guide line. thanks
this AttachDbFilename=|DataDirectory|\DbProduct.mdf
should be AttachDbFilename=|DataDirectory|DbProduct.mdf
You don't need to add \
Have a look at this Using connection strings from web.config in ASP.NET v2.0