after changing asp.net mvc3 connectionstring, asp.net configuration dont work - asp.net

i have a problem with the asp.net MVC3.
when i create a new project and start the asp.net configuration my browser opens and i can edit e.g. the user.
but when i change the connection string to my external server or to my local sqlexpress server, i get the message after the browser pops up:
The type "MyApp.MvcApplication" could not be loaded.
what do i wrong? my connection string looks like:
<add name="ApplicationServices"
connectionString="Data Source=my-pc\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />

Looks like the type hasn't actually been built and packaged as a DLL into the bin folder. Did you try running the project initially before making the change?

Related

ASP.NET VB change db connection on web forms framework

I have created an instance of ASP.NET Web Forms in my Microsoft Visual Studio. By default the program generates user login page and registration which are linked to the .mdb file.
I want to reconfigure the standard connection and link it to my instance of MSSQL 2012 SQLExpress server.
How can I do it?
Ok so I will give some direction and link you to a page.
First let me ask you this the connection you are using presently is it in a web.config file. If so this is where you will change the server/instance and database/catalog name.
Web.Config modification for SQL Server Instance
or this link
Web Config modification for SQL Express 2
So if you in the web.config file you should see something similar to this.
<ConnectionStrings>
<add name="" connectionString="Server=(localhost)\SqlExpress;Max Pool Size=300;Initial Catalog=database;User ID=username;Password=password;" providerName="System.Data.SqlClient"/>
</Connectionstrings>
or
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source= (LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\database.mdf;Initial Catalog=database;Integrated Security=True" providerName="System.Data.SqlClient" />
you need to change the follow:
Server or Data Source
and
Initial Catalog or AttachDbFilename
Now your credentials you may use any username and password that has access to the sql server express instance.
I hope this helps.

Why is my web.api project still looking for an .mdf file?

I have a code first web.api project that was working fine with the automatically created .mdf in the App_Data folder. I decided to move my app to IIS and modify the app pool config to load the user profile, again, no problem. Then I loaded the .mdf in visual studios sql explorer and at that point, the app pool login from the web app started failing. No clue why and couldn't fix it, so I decided to use sql express instead of waste more time on it. So, I installed SQL Express, killed all my migrations, and modified the web.config connection string to:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=SSPI"/>
</connectionStrings>
When I try to use migrations to update-database or run the api app, I get an exception saying
Cannot attach the file
'C:\Users\Source\MyApp\Main\Solution\MyApp.API\App_Data\MyApp.DataService.DataModel.AppEntities.mdf'
as database 'MyApp.DataService.DataModel.AppEntities'.
Well, that makes sense since I deleted it, but why is my app still trying to connect to the .mdf file? It's gone and I've changed the default connection. I've searched the solution for anything referencing the .mdf file, but nothing shows up. What am I missing?
I finally figured out that I had to name my connection string the same as my DbContext class, so in my case:
<connectionStrings>
<add name="AppEntities" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=SSPI"/>
</connectionStrings>
to match my DbContext derived class
namespace MyApp.DataService.DataModel
{
internal class AppEntities : DbContext

ASP.NET IDENTITY WEB FORMS

OK. I am experiencing something very strange with the asp.net identity in web forms. I setup the web.config file to establish connection to my local sqlexpress server. I previously created a database and ran the web application which uses asp.net identity and the 4.5 .net framework. The first time I ran the web app the tables were automatically created for me in the sql server database but then I noticed that in the APP_DATA folder under the solution there was another database created with a name aspnetdb.mdf
Although I have pointed out that the connection string connects to the sql server for some reason the web app connects to the newly created localdb database located in APP_DATA.
Am I doing something wrong here?
thanks
Oddly enough I have just come across this very issue in our codebase. One of my developers was using the 'old' Role provider to check if user was in a particular role. This was causing the app to create the database in App_Data as the config for all that still exists in machine.config. The connection string and provider details are specified in machine.config, so your web.config will only add or remove them. So for example if your machine.config says:
<connectionStrings>
<add name="LocalSqlServer" connectionString="..."/>
</connectionStrings>
And your web.config has this:
<connectionStrings>
<add name="MyConnectionString" connectionString="..."/>
</connectionStrings>
Your application will be able to see and use both strings. To fix it you can clear the connection strings first like this:
<connectionStrings>
<clear />
<add name="MyConnectionString" connectionString="..."/>
</connectionStrings>
But that still leaves the underlying problem that the old role (or profile) provider is being used in code. so you will instead get lots of errors when using it. You need to switch code like this:
if (User.IsInRole("Admin"))
{
//Do admin stuff
}
To something like this (in my case _userManager is of type UserManager<User> and is injected into my controller constructor at runtime.
var user = _userManager.FindById(User.Identity.GetUserId());
if (_userManager.IsInRole(user.Id, "Admin"))
{
//Do admin stuff
}

ASP.NET: How can I explore the default user database

So if I create a new MVC project with basic log in template, there should be somewhere a database which contains all the user login information. There's even the default connection string which points to it.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MyProjectName-20140521042155.mdf;Initial Catalog=aspnet-MyProjectName-20140521042155;Integrated Security=True" providerName="System.Data.SqlClient" />
How ever, when exploring the project folder I cannot find it. I also tried to turn on "show all files" option in the solution explorer.
Sql Server Management Studio can be used to connect to the local db server. You can also use visual studio server explorer.

asp.net| change the place webforms save user data

I am trying to change the place my webform saves the data.
What I mean is, when you open a Visual Stuido/C# Web App, its has a user login/register data.
The default data is saved in your project folder, in APP_DATA as: ASPNETDB.MDF.
What about if I want to use MSSQL Server 2008R2.
How can I change it?
Just setup a new database and change your connectionstring in the web.config:
Using SQL Server instead of ASPNETDB.mdf
<connectionStrings>
<add
name="NorthwindConnectionString"
connectionString="Data Source=serverName;Initial
Catalog=Northwind;Persist Security Info=True;User
ID=userName;Password=password"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
How to: Read Connection Strings from the Web.config File
in really server MS Server 2008R2 you must doing backup from your "home" datafiles: "in APP_DATA as :ASPNETDB.MDF"
p.s. sorry for my bad English.

Resources