Default account controller not creating database in MVC 5 - asp.net

I am creating a web application in ASP.NET MVC5. when i created the project a controller named AccountController was added automatically with all the necessary functions. now when i run the application and register a new user or try to login it gives some error. When i run it, it should create a database in App_data but its not creating any database and giving the following error. can anyone help me solve it please
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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
the connection string is:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-EmployeeOrderSystem-20160710042802.mdf;Initial Catalog=aspnet-EmployeeOrderSystem-20160710042802;Integrated Security=True" providerName="System.Data.SqlClient" />
if any other detail is needed please ask. Thanks in advance

When you create a new MVC 5 application and choose "Individual User Accounts", a new ASP.NET Identity Provider is included which uses Entity Framework 6 Code-First.When Identity is accessed for the first time, Entity Framework checks to see if the database exists. Unless configured otherwise, it uses the "DefaultConnection" to find the identity database. If the database does not exist when Identity is called, EF automatically created the database.When the first user is registered, database to be created.

Related

Application services functionality lost in Azure

I have a ASP.NET application that uses application services to manage user roles. This application worked fine when I was using a local database. When I transitioned to Azure, the main data tables still work but I am unable have user's login or create new accounts because the Application table cannot be found. Previously, the application services created these tables automatically when using a local database. The connection string name appears accurate. This is my first attempt at Azure...is there something I'm missing?
The error is "The entity type Application is not part of the model for the current context"
For additional context: When I try to create the membership tables in the Azure database using aspnet_regsql.exe, I get the following error: "An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 40508 and the SqlException message is: USE statement is not supported to switch between databases. Use a new connection to connect to a different database."

trouble connecting to LocalDB in Visual Studio

I'm going through the Contoso University tutorial found here on asp.net and can't get past the first part due to connectionString problems.
I'm getting this error message after i enter the connection string and try to view the database.
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: SQL Network Interfaces, error: 50 - Local Database Runtime
error occurred. Cannot create an automatic instance. See the Windows
Application event log for error details.
I was looking at this msdn blog which mentions the same error under the "Deploying LocalDB on IIS Server " section but i honestly have no idea what it wants me to do.
How can do i fix this error? Is it a problem with the tutorial or am I missing something?
Thanks in advance.
Any chance it is because you forgot to double-escape the backslash? Did you try this:
"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Or even better, you could just use the # mark to disable character escaping for the entire connection string:
#"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Here is what i do in order to fix this problem
You need to install the sql server local db
Copy the local server of your local db in case you don't know here is how to find the local server name(You need to copy the highlighted part)
Update the local server name in the connection string in the web.config file of the Contoso Project
Note that you only need to update the server name in you connection string do not replace the whole connection string with the server name.
Re run all the migration one by one like this
update-database -TargetMigration MigratonName
Build the project and run it.
Change application pool identity from ApplicationPoolIdentity to LocalSystem in IIS for your website application pool and IntgretedSecurity = true in config
will help you.

Sql Server Error Caused by Web Part

I am using webparts to create a dashboard page. To do that i am dynamically loading the webparts.
strZoneNumber = "zone" + intCnt.ToString();
UserControl UC = (UserControl)LoadControl(row["c_widget_path"].ToString());//Loads the usercontrol
UC.ID = row["c_widget_webid"].ToString();
UC.Attributes.Add("Title", row["c_widget_webid"].ToString());
//UC.Attributes.Add("title" , "Test");
GenericWebPart ucwebPart = wpmDashBoardManager.CreateWebPart(UC);//creates a webpart
wpmDashBoardManager.AddWebPart(ucwebPart, wpmDashBoardManager.Zones[strZoneNumber], ZoneIndex);//adds it to a zone
wpmDashBoardManager.Zones[strZoneNumber].Visible = true;
My webpartmanager personalization mode is set to 'true'
While running this page on the server it is giving me the following error:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance 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.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory.
The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.**
Any ideas as to what might be causing this and solutions? Help would be greatly appreciated :):)
Many features of ASP.NET rely on intrinsic application services such as membership, roles, profiles, and personalization. For example, the ASP.NET personalization service uses a personalization provider to save personalized user settings on Web pages. By default Web Parts try to save personalizations into SQL Express database.
This solution was helpfull for me.
In connectionStrings section of your web.config file remove LocalSqlServer connection and add it again with your own preferences:
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="yourConnectionString" providerName="System.Data.SqlClient"/>
</connectionStrings>
Then if you will have 'Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion' error you should create a new database for you to use for personalization.
So, just explore C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe and go through steps of the wizard.
Hope it will help.

MVC 3 ASPNETDB.MDF SqlExpress Database Connection String on Web Hosting

I think this is more of a connection string issue that MVC 3, so sorry in advance.
I've created a website in MVC 3 with the default database that is created when you register a new user. It works fine local but not on my web hosting where I receive the following error:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
The default connection strings are:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
Should I specify a connection string with an explicit IP address of the server or retain the .\SQLEXPRESS command? If I need to specify a username and password then what should I use? I've never used a local SQLExpress database before so I'm clueless (which I'm sure is apparent).
If you cannot use SQL Express, then you could consider an embedded SQL Engine:
SQL Compact Edition or SQLLite
I've never used SQL CE, but SQLLite is just a single DLL.
Obviously you don't have all the features of a fully fledged database engine, but they are still pretty powerful.
Generally you will need use a connection string with a specific IP Address, Username, Password, etc.
Who are you hosting with? Generally a .net host provider will give you the connection string to use to connect to your database. You can copy and paste in to you web.config. Also, when they create the database for you, they generally specify the username, password, and database name so you will have to change all of that.
This is visual studio has Web.config.debug and Web.config.Release with the xml transformations. This way when you publish to the site, the connection string is automatically changed from your local connection string to the connection string used in your production environment.
You probably need to follow this article?
http://www.asp.net/mvc/tutorials/authenticating-users-with-forms-authentication-cs
Deafault ".net" installs Application Services to "AttachDBFilename=|DataDirectory|aspnetdb.mdf"
Then you create your own DB and now you're using two DB's to store data that could just be in one.
If you read the above article it shows you how to combine everything into one DB.
When you deploy to the hosting server (and it has a limit on how many DB's you can use or isn't even running sqlexpress) neither DB attach. So you need to make a "transform file" for your web.config file (usually Debug and Release) which is basically another web.config but only with the lines of config in that you need to change when the site is deployed to the hosting server.
So your hosting provider will give you the details needed for the connection string on the server. You then put that in the "web.config.release" file and when you compile and publish the "release" version of your site you will get a web.config file that has the correct connection string data in.

asp.net mvc unable to connect to SqlServer when creating the users from Register page

I have Visual studio 2008 and Installed MVC2 RTM.
For data base I have Sql Server 2008.
When I first create a project of type "asp.net mvc web application"
I get the default structure of the project and app_data.
After I run the project and trying to Register a new user It is giving the following error.
The user instance login flag is not supported on this version of SQL Server. The connection will be closed.
The above message is displayed, while the connection string value is
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
I'm getting the below error when data source=.\SQLEXPRESS
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Any Idea Why it is not connecting to the data base?
Thanks in advance.
It looks like you're using a full SQL Server.
Based on the link in Anand Kumar M's comment, you can't use AttachDBFilename when you're using a full SQL server, so try removing that from your connection string and attaching the database to your SQL server
For attaching the database to your SQL Server instance.
http://msdn.microsoft.com/en-us/library/ms190209.aspx
Once you've done that, remove the AttachDbFilename clause from your connectionstring and replace it with the following:
Initial Catalog=Mydatabase;
Where MyDatabase is the name of the database as it shows in SSMS.
Hope this helps

Resources