Entity Framework connection string error - c#

I have this connectionstring in app.config
<appSettings>
<add key="CBREEntities" value="metadata=res://*/CBRE.csdl|res://*/CBRE.ssdl|res://*/CBRE.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" />
<add key="elmah-sqlserver" value="data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True" />
</appSettings>
and this in web.config.cshtml
<connectionStrings>
<add name="CBREEntities" connectionString="#Model["CBREEntities"]" providerName="System.Data.EntityClient" />
<add name="elmah-sqlserver" connectionString="#Model["elmah-sqlserver"]" providerName="System.Data.SqlClient" />
</connectionStrings>
Entity framework generates this connection string in web.config file
<connectionStrings>
<add name="CBREEntities" connectionString="metadata=res://*/CBRE.csdl|res://*/CBRE.ssdl|res://*/CBRE.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
<add name="elmah-sqlserver" connectionString="data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
and after running app I have this error
It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
already tested replacing ' with " and replacing entityclient to sqlclient

Try delete your connectionStrings in your web.config.cshtml
I'd never put connectionstring in web.config.cshtml and all my applications woks fine.
I hope help!

Related

What changes are needed for connection string server to local (SQL Server)

The connection string works well on server, but I get an error when I run in my local SQL Server.
<add name="FoodDbConString"
connectionString="data source=LAPTOP-NF1LM193\SQLEXPRESS;Database=FoodData;"
providerName="System.Data.SqlClient" />
Server connection string :
<add name="FoodDbConString"
connectionString="Server=191.167.1.280;Database=FoodData;User Id=aa;Password=alpha#123;"
providerName="System.Data.SqlClient" />
Local Connection string : (Error)
<add name="FoodDbConString"
connectionString="data source=LAPTOP-NF1LM193\SQLEXPRESS;Database=FoodData;"
providerName="System.Data.SqlClient" />
Error:
System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.

Underlying provider failed to open when I convert database property to do not copy

This is the connection string and when I change the property of the database file (database1.mdf) to "do not copy", it causes an error.
<connectionStrings>
<add name="ClassLibrary1.Properties.Settings.Database1ConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
That's probably because of AttachDbFilename=|DataDirectory|\Database1.mdf that you can't not copy the database to the DataDirectory.
The connection string tries to find and attach the database from the given address and it can't find it. you can attach the db first and then use this connection strings:
<add provider connection string="data source=.;
initial catalog=Database1;
integrated security=True;/>

WPF app SQL connection string error

This question has probably been asked a thousand times but all the answers that I have seen are not relevant to my question.
I have an asp.net web site setup locally to connect to sql and I used the exact same connection strings in the WPF App.config file
<connectionStrings>
<add name="TrackingConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SHIPPING; User Id=sa; Password=password" />
<add name="RMAConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=FRTOOLSRMA; User Id=sa; Password=password" />
<add name="PickListConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=Picklist; User Id=sa; Password=password" />
<add name="ShipWorksConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=ShipWorks; User Id=sa; Password=password" />
<add name="SupplyConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SupplyManager; User Id=sa; Password=password" />
</connectionStrings>
As usual this works on the local machine but on the network machine I get a "A network-related or instance-specific error occurred while establishing a connection to SQL Server." error.
Like I said this connection string is copied exactly from the asp.net web application, web.config file connection string which the network machine consumes fine. I have the App.config properties set to Copy always also the Sql server configuration is set up to enable Named Pipes and TCP/IP. Windows Firewall has port 1433 open. I thought the Copy always property being set would have solved the problem since the program wouldn't work because images were causing it to break until I set their properties to copy always. I've restarted the SQL Server and machine.

appharbor [Win32Exception (0x80004005): The system cannot find the file specified] with model first EF

I have a small project where I used continuous integration with bitbucket and appharbor When I published the project the login is working normally and so on but other database connections gives the following error:
The system cannot find the file specified
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified
here are my local connection strings
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ZeinyCenter-20130614160141;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
<add name="Model1Container" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=(LocalDb)\v11.0;initial catalog=aspnet-ZeinyCenter-20130614160141;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
and here is the appharbor connection string
Server=576666e4-329e-4511-95b9-a1dd00ff4766.sqlserver.sequelizer.com;Database=db576666e4329e451195b9a1dd00ff4766;User ID=yusmzpttdopksbua;Password=H3Ex6jp3wihobPu3W2KZHBpW7tDk8SWtxYWTxabXGXhVBGTAnRJZz6AgLRzKNe4L;
Can someone please help me
I solved my problem typing the connectionString that appharbor gave me on the Web.config.
Steps:
1) Go to appharbor and select your application.
2) Click on add-on, and select SQL Server (install the free one).
3) Then click on Go to SQL Server.
4) Scroll to the bottom and you will see Connection string.
5) Copy all (Click it and press ctrl+A), the part that says Server=bla bla bla.
6) Now go to Visual Studio --> Web.config and paste it in:
add name="DefaultConnection"
connectionString="Your appharbor connectionString"
providerName="System.Data.SqlClient" />
Example, mine was like this:
add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;
Initial Catalog=aspnet-DeliveriandoWebApp-20131019135542;
Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|\aspnet-DeliveriandoWebApp-20131019135542.mdf"
providerName="System.Data.SqlClient" />
Now is like this:
add name="DefaultConnection"
connectionString="Server=8a6b279b-0441-49c7-a97e-a2860049ea89.sqlserver.sequelizer.com;
Database=db8edfdf6c279c044149e7a17ea2860049ea89;
User ID=lolyctkwkaebnkj3;
Password=nYhP4hZKDNMLftEaSyeeeS8eVpbs3H3seUZQUQ8PZzMRXA5hPVfDirfPwZzHfvaFDsz;"
providerName="System.Data.SqlClient" />

How do I build the database connection string if the website is on the same server as the db?

I have a problem with my connection string and I couldn't find anything on the web that could help me. So I have a test website on which I connect to a database which is not on the same server. There it all works fine, the data is being read correctly and the connection is successful.
Now when I try the same on a website which is on the same server than the database it doesn't work. So I figured I can't just connect to the database server as I would from a different server if I am already on that server like this:
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=serverName;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Could anyone help me with that?
If you need more information just ask please.
Thanks in advance!
[edit]
Oh I forgot...this is the error message I get:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Try localhost instead of server name
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=localhost;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=.;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Both answers above are correct, however, if you have SQL Express installed (I assume we're talking about MS SQL) then your connection string must be something like this:
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>

Categories

Resources