i have changed the connection string to point to a database in the remote server. But when I execute the project the program still points to the local db.
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="TEDALS_Ver01.DAL.TedalsContext"
connectionString="Data Source=FE0VMC0643\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\TeDaLSdev.mdf;
Integrated Security=False"
providerName="System.Data.SqlClient"
/>
<!--<add
name="TEDALS_Ver01.DAL.TedalsContext"
connectionString="Server=FE0VMC0643; Database=TeDaLSdev; "
providerName="System.Data.SqlClient" />-->
<!--<add name="TEDALS_Ver01.DAL.TedalsContext"
providerName="System.Data.SqlClient"
connectionString="Server=FE0VMC0643;Data Source=FE0VMC0643;
Initial Catalog=TeDaLSdev;
Integrated Security=True;
Connect Timeout=15;
Encrypt=False;
TrustServerCertificate=False;" />-->
</connectionStrings>
Comments are the different connection strings i have treid so far. i never had a connections string when I was using the LocalDB.
Constructor for Connection
public class TedalsContext : DbContext
{
public TedalsContext()
: base("TedalsContext")
{
//Database.SetInitializer<TedalsContext>(null);
}
}
i am using SQL Server Express as my database. I have also tried changing the name of the parameter for base in constructor as the name of the Database. But it did not change anything.
I have already tried if I have access to the database through SSMS. I am able to create tables but I am unable to rename the database as such(I do not have access rights to rename the database TeDalSdev).
Are there any other work around i could try? Should the name of the remote database and the local database should be the same to avoid changing a lot of code?
UPDATE
Controller
public class LsystemFamiliesController : Controller
{
private TedalsContext db = new TedalsContext();
//Code goes here
}
I've added a connection string from a web config file of one of my projects and all the fields that (should) be checked. This is within the <connectionStrings> tags. You need to make it your default connection and you can only have one connection string as the default connection.
<add name="DefaultConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=Providedbyhost;integrated
security=false;Initial Catalog=DB_Name;User Id=UserId;Password=password;
Trusted_Connection=false; TrustServerCertificate=true;
Encrypt=true;MultipleActiveResultSets=True" />
Where you have your DB Context:
public TedalsContext()
: base("DefaultConnection")
Switch everything to DefaultConnection, until you get it working, then you can focus on changing names. Comment out your local db connection strings. Even remove it from the project if you need to (and save it elsewhere), while you are testing this.
I've also added a screen shot of the my folder directory, to show which web config folder I am modifying. See it's highlighted in blue.
Also this screen shot shows you where to navigate to test your connection string within VS.
I suggest you look here:
How to: Access SQL Server Using Windows Integrated Security
What will be the connectionstring for mssql windows authentication
and this:
Connection string using Windows Authentication
As I suggested in the discussion. I recommend also contacting web hosting provider, as I have had this problem where it will not connect and it's been a problem at the hosting end.
If you need more help, shout out.
Under your TedalsContext constructor, use : base(connectionStringName).
Otherwise, the context will treat it as code first and create a TedalContext inside your SQLExpress Local DB.
public class TedalsContext : DbContext
{
public TedalsContext()
: base("TEDALS_Ver01.DAL.TedalsContext")
{
//Database.SetInitializer<TedalsContext>(null);
}
}
Related
Sorry, I have a feeling this is a really basic question, but my connection string to my data source is invalid. I did a bit of trouble shooting and think that I am missing the metadata part of the connectionstring - but I'm not sure where it is/how to create it.
How is how I think it should look
<add name="PDCWebEntities" connectionString="metadata=METADATASTRING;Data Source=.;Initial Catalog=PDC;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
And here is where I think the information that needs to be in the metadata string is held:
It should be noted that the app.config file where the connectionstring is is in the PokemonDayCareSimple.Web project
Is it possible to make the metadata part of the string from this information?
You don't need metadata for connectionString.
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\me\source\repos\MarketplaceMVC\MarketplaceMVC.Web\App_Data\MarketplaceIdentityDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
Instead of "AttachDbFilename" you can use also "Initial Catalog".
In your Context Class you need to add a constructor:
public ApplicationContext() : base("DefaultConnection")
{
}
I decided to learn how to make a simple ASP.Net project, with a reference to a database project through the Repository Pattern.
I have my Controller calling for a List<Weight> to handle:
public IActionResult MyWeight()
{
var repo = new Database.Repositories.WeightRepository();
var data = repo.GetWeight().Result;
return View(data);
}
When repo.GetWeight() is called, I get an AggregateException error, with an inner exception saying:
"No connection string named 'MyDatabaseConnection' could be found in the application config file."
So for clarity, let me outline the solution's structure:
aspProj
Controllers
Views
Service
App.config (1)
Web.config
...
Database
Entities
Repositories
App.config (2)
...
Database.Test
Test.cs
App.config (3)
...
I've added the following connectionString to all App.configs and the Web.config:
<connectionStrings>
<add
name="MyDatabaseConnection"
connectionString="Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I have tested the database both from Visual Studio's Server Explorer, and through the Test.cs file from the test-project. I can insert data and retrieve without a problem.
But when the ASP.Net-part wants to access it, there is no love.
I thought it might be the ISS which did not know the path from where it is...
Any thoughts?
__
Edit:
My Web.config:
My AppSetting.json:
Well the problem is clear - ASP.NET is trying to access the database using a connection string with the name MyDatabaseConnection:
<connectionStrings>
<add name="MyDatabaseConnection" connectionString="put the connection to the db here..." />
</connectionStrings>
And in your Web.config you only have a connection string with the name WeightDatabaseConnection:
<connectionStrings>
<add name="WeightDatabaseConnection" connectionString="put the connection to the db here..." />
</connectionStrings>
Just add a new element for MyDatabaseConnection under <connectionStrings> in the Web.config file and it should work
this is my connection string on godaddy hosting. By the way I have my database and membership database I makes security for some pages on my website.
All tables in one database Waves database. I used it to make login page for admin panel for my website but when I try to login and write pass & username it makes error that I write it above and this my connection string in web.config .also i have another 2 connection strings but it works OK, only this connection string is not working.
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=180.000.004.53\SQLEXPRESS;Integrated Security=false;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
User ID=id;Password=Password;Encrypt=False;
providerName="System.Data.SqlClient" />
<add name="WavesEntities"
connectionString="metadata=res://*/App_Code.WaveModel.csdl|res://*/App_Code.WaveModel.ssdl|res://*/App_Code.WaveModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=004.00.004.03;User ID=id;Password=password;Encrypt=False;Connect Timeout=15;Initial Catalog=Waves;Integrated Security=false;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
<add name="WavesConnectionString"
connectionString="Data Source=000.100.10.0;User ID=id;Password=password;Encrypt=False;Connect Timeout=15;Initial Catalog=Waves;Integrated Security=false"
providerName="System.Data.SqlClient" />
</connectionStrings>
After a minor reformatting of your code, it seems pretty obvious that the first connection string is invalid, and may be causing your problem:
This part should presumably be placed within the quotes, and be part of the connection string:
User ID=id;Password=Password;Encrypt=False;
i registered my website on somee.com. for that i have uploaded MS SQL database. i was wrting this connection string in my code:
connectionString="metadata=res://*/nrcsaEntities.csdl|res://*/nrcsaEntities.ssdl|res://*/nrcsaEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=My-PC;initial catalog=nrcsa;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
now as i registered somee.com is providing me new connection string that is:
workstation id=nrcsadb.mssql.somee.com;packet size=4096;user id=DuaZoya_SQLLogin_1;pwd=abcd;data source=nrcsadb.mssql.somee.com;persist security info=False;initial catalog=nrcsadb
i have changed connectiong string in file web.config by replacing this first connection string with provided connection string by somee.com
PROBLEM:
This replacement is generating warning that:
System.ArgumentException: Keyword not supported: 'user id'.
how to solve this problem?
In the web.config file ....
<connectionStrings><add name="nameofConnection" connectionString="Data Source=servername; Initial Catalog=DatabaseName; User ID=UserName; Password=Password;"/> </connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0" /> </system.web>
you can edit target Framework according to you.
from : http://dotnet-developers-cafe.blogspot.in/2013/08/create-connection-string-in-aspnet.html
You're using Entity Framework.
Entity Framework has its own connection string which contains a reference to the EF metadata (metadata=...) as well as the inner connection string to connect to the actual database.
You need to insert your actual database connection string inside the EF connection seting, in the provider connection string=... section.
You will also need to add multipleactiveresultsets=True to their connection string; EF needs that setting.
As you are using entity famework, then your connection string will look like
<connectionStrings>
<add name="BlogContext"
connectionString="metadata=res://*/BloggingModel.csdl|
res://*/BloggingModel.ssdl| res://*/BloggingModel.msl;
provider=System.Data.SqlClient
provider connection string="data source=[you somee.com connetion string];"" providerName="System.Data.EntityClient" />
</connectionStrings>
what you need to do is simply change the value of data source from the actual connectionstring provided by somee.com
Don't replace the whole connection string. You will need to remove the Integrated Security = true section and replace it with user=DuaZoya_SQLLogin_1;password=abcd.
Also change the data source to nrcsadb.mssql.somee.com.
You pretty much just need to replace values in your existing connection string with the values provided.
I am getting the following error trying to connect to DB2 Entity with .Net 4.0
The underlying provider failed on ConnectionString.
I get it on this line within the generated code of my entity cs file
public DOCUMAKRContainer() : base("name=DOCUMAKRContainer", "DOCUMAKRContainer")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
My App.config (which is created when you create entity the looks like this
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections />
<connectionStrings>
<add name="DOCUMAKRContainer"
connectionString="metadata=res://*/Documakr.csdl|res://*/Documakr.ssdl|res://*/Documakr.msl;provider=IBM.Data.DB2;provider connection string="Database=DCCPDEVL;User ID=documakr;Password=Dcpd#123;server.com:60000"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
I have tried to delete and rebuild the entity and get the same results every time. All of this is generated code when you add an entity object, so I am wondering if it is a VS 2010/IBM DB2 issue. Internet has not really given me any help.
Thoughts?
This site is a good resource: http://www.connectionstrings.com/
It looks you have have some garbage in your connection string:
provider connection string="Database
Actually, it looks like you've got a conection string jammed into your connection string.
Also, you might want to edit your post and remove or ##### the login info.