ConnectionString Error on publish in web server - c#

I have a project in asp.net MVC with Entity Framework and my connectionsString at web.config
<add name="DefaultConnection" connectionString="data source=localhost;Initial Catalog=telexpo_bd;Integrated Security=SSPI;User Id=telexpo_bd;Password=hey76jdhdyU;" providerName="System.Data.SqlClient" />
<add name="telexpoEntities" connectionString="metadata=res://*/telexpoEF.csdl|res://*/telexpoEF.ssdl|res://*/telexpoEF.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=telexpo_bd;integrated security=True;user id=telexpo_bd;password=hey76jdhdyU;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
this work perfectly in my PC when I emulate via Visual Studio but when I publish my application in web server doesn't work. Give the error page built by me but I was connected my web server company and after long talks they give to me this error:
Configuration Error
Description:An error occurred during the processing of a configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is
empty.
Source Error:
Line 255:
Line 256:
So, my web.config just have 193 lines and the error in web.config is at line 259!??
I was investigate by 'LocalSqlServer', "AspNetSqlMembershipProvider" and doesn't found nothing...
After some investigation across the web I found that one which generated the AspNetSqlMembershipProvider and LocalSqlServer was the machine.config at C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config so I was thinking at server was the same but I can't change it because I have a dedicated server.
After time and tried a lot of things...but I can't find the solution about it... they insist the problem is about connectionstring. How could be?
Can someone give some suggestions please?

Yes it is because of connection string, that it cannot find the connection string value under the name 'LocalSqlServer'. Try changing the connection string that matches the server in the app.config file. If you have separate projects for web and entity then include the connection string in the web.config file of web application which will resolve.

Related

host a database website with entity framework in the production server

I developed an asp.net website (using webforms) and for database connection I used Entity Framework. On my local computer everything is working fine. Now I try to host it I am having a problem. I have copied my files to the production server and attached my SQL Server database and set my connection string to:
<add name="ConnectionString"
connectionString="Data Source=SQL5003.Smarterasp.net;Initial Catalog=DB_9C4561_WFormBlog;User Id=DB_9C4561_WFormBlog_admin;Password=mydbpwd"
providerName="System.Data.EntityClient" />
but when I test my website am getting error:
Keyword not supported: 'data source'
When I removed "data source", it started complaining of "Initial catalog" keyword not supported.
Please help me out. You can refer me step by step tutorial or material that can put me through. Thanks in advance!
Try the below format, I have my database on smarterasp.net and it works well
<connectionStrings>
<clear />
<add name="ConnectionString" connectionString="Persist Security Info=False;database=DB_9C4561_WFormBlog;server=SQL5003.Smarterasp.net;user id=DB_9C4561_WFormBlog_admin;password=mydbpwd;Current Language=English;Connection Timeout=60;" />
</connectionStrings>

How to connect ASP.NET config to SQL Server instead of SQL Server Express?

I configured my SQL Server database using aspnet_regsql.exe. Everything worked great. I then added the new connection string in my web.config file:
<connectionStrings>
<clear />
<remove name="LocalSqlServer" />
<add name="SQLConnectionString"
connectionString="Provider=ProvName;Server=Sname;Database=dbName;Uid=user; Pwd=pWord" />
</connectionStrings>
When I try to access the database from the website I get an error:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Source Error:
I am running this site on IIS via Visual Studio 10. Any ideas what steps I'm missing?
<add name="LocalSqlServer" connectionString="Data Source=.;Initial Catalog=DBName;Uid=user;Pwd=pWord" provider="System.Data.SqlClient"/>
Something like above should work.
Your code is looking for a connection string named "LocalSqlServer", yet you are adding a connection string named "SQLConnectionString".
Change this to:
<add name="LocalSqlServer" connectionString="Provider=ProvName;Server=Sname;Database=dbName;Uid=user; Pwd=pWord" />
Do a search for the phrase "LocalSqlServer" in all your config and code (.cs?) files. It is being references somewhere else...not just the connection-strings config area.
The "name" attribute is used in other places in the code to look up the actual connection string.
I like Agent Ransack for looking in files for a specific string.
When you find the other reference, you can replace it with "MySuperSpecialConnectionStringName" (as seen below, an alteration of your original code).

the Error "Connection string not found in application config file" occurs EF 6.1.1, even though it is in the Web Config for the project

I have a WCF service base on the .net framework 4.5.1 that uses several DLLs built around the EntityFramework 6.1.1 , I use them in multiple web sites and web services, but it seems that suddenly all new WCF projects I create cannot find the connection strings. The error is
"No connection string named 'MemberEntities' could be found in the application config file." Connection string name 'MemberEntities' will of course vary depending on what model I am trying to access.
<connectionStrings>
<add name="CoachingEntities" connectionString="metadata=res://*/CoachingModel.csdl|res://*/CoachingModel.ssdl|res://*/CoachingModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SomeServer.com;initial catalog=CoachDB;persist security info=True;user id=SomeUser;password=SomePasswd;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"/>
<add name="MemberEntities" connectionString="metadata=res://*/MemberModel.csdl|res://*/MemberModel.ssdl|res://*/MemberModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SomeServer.com;initial catalog=MembersDB;persist security info=True;user id=SomeUser;password=SomePasswd;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"/>
<add name="QuestionnaireEntities" connectionString="metadata=res://*/QuestionnaireModel.csdl|res://*/QuestionnaireModel.ssdl|res://*/QuestionnaireModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SomeServer.com;initial catalog=QuestionnaireDB;persist security info=True;user id=SomeUser;password=SomePasswd;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"/>
</connectionStrings>
All of the connection strings have been added to the web config (as shown) for the WCF project just as I have added it to all of the Asp.Net web forms applications in the past, all of which work fine. I have created new clean solutions multiple times and they all have the same problem.
I have previously done the same with WCF web services. Is there some new requirement or something else that I could be missing? I have seen this error before but copying the connection string from the Class project’s app config to the WCF or Website’s web.config has always solved the problem until now.
Any thoughts or ideas would be greatly appreciated. I am using Visual Studio 2013 Pro on Windows 8.1

Connection to SQL Server Database inside Visual Studio connectionString error

I've import my SQL 2005 database to my project and i am trying to connect to the database using the web.config
But I've this error when I add the connectionString to the web.config.
<add name="strConn" connectionString="Data Source=.\sqlexpress;Initial Catalog=intranet_db;Integrated Security=True"
providerName="System.Data.SqlClient"/>
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Detailed Error Information:
Module IIS Web Core
Notification Unknown
Handler Not yet determined
Error Code 0x80070032
Config Error The configuration section 'add' cannot be read
because it is missing a section declaration
Config File \?\C:\Users\user\Documents\Visual Studio
2012\Projects\test\test\web.config
Requested URL localhost:64198/
Physical Path
Logon Method Not yet determined
Logon User Not yet determined
Request Tracing Directory
C:\Users\user\Documents\IISExpress\TraceLogFiles\
Am I doing it wrong? What should I add in the web.config?
Thanks.
Please make sure you put the "add" tag in the correct place. I'm able to reproduce your error when I place it i wrong section. Your web.config file should look like this:
<configuration>
<connectionStrings>
<add name="strConn" connectionString="Data Source=.\sqlexpress;Initial Catalog=intranet_db;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
it should be something like this
<connectionStrings>
<add name="connectionString" connectionString="Provider=SQLOLEDB.1;Data Source=dbhostname;Persist Security Info=True;Password='password';User ID='username';Initial Catalog=dbname" />
</connectionStrings>
have a look at http://www.connectionstrings.com/ it has examples of what they should be.
looking at you connection string make sure the instance name ./SqlExpress is correct.
A quick test would be to load sql manager and connect with the ./SqlExpress
Standard Security
Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;
Trusted Connection
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
to give you a better answer would require knowing how you want to connect to the database.

What should be the connection string for a default profile provider in windows azure?

I am using system.web.providers to implement basic authentication for my APIs in my windows azure project. This is my default connection string which am using
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-myProject.WebRole-20130117071735;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-myProject.WebRole-20130117071735.mdf;MultipleActiveResultSets=True" />
And in my AppData folder the .mdf file is being created. But when i deploy to my azure account am getting the following error.
{"Message":"An error has occurred.","ExceptionMessage":"The system cannot find the file specified","ExceptionType":"System.ComponentModel.Win32Exception","StackTrace":null}
I know the error doesnt give any information, but this is happening only for the APIs i have put the basic authentication so i guess the problem is that .mdf file isnt being created on cloud.
Any idea what the connection string should be when I deploy to cloud?

Categories