I have a database hosted on somee.com and I use it for my Membership, Roles and other information tables.
However, by now I only experienced minor troubles with ASPNETDB.mdf that is automatically generated by the ASP.NET Web Administration tool, so I deleted it sometimes and let the tool re-create it, so that some Roles problems will be fixed on the website.
Yesterday I didn't manage to delete it because Windows kept saying it's in use by some other application, so I simply opened the task manager and closed all SQL related tasks. Then, I managed to delete the aspnetdb file, but the tool did not re-create it!
Today I tried again and still, aspnetdb.mdf is not being generated, and also there are no SQL related tasks on task manager :(
If I can just have roles and EVERYTHING without aspnetdb.mdf, just on the somee.com database, I'll be thankful for a solution. Here are some web.config details:
<connectionStrings>
<add name="MembershipProviderDB" connectionString="workstation id=medinadb.mssql.example.com;packet size=4096;user id=user;pwd=password;data source=medinadb.mssql.example.com;persist security info=False;initial catalog=medinadb" providerName="System.Data.SqlClient"/>
</connectionStrings>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MembershipProviderDB" applicationName="AmedinaKom" enablePasswordRetrieval="false" enablePasswordReset="true" requiresUniqueEmail="true" passwordFormat="Hashed" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0"/>
</providers>
</membership>
I'm using the MembershipProviderDB for all usages, though APP_DATA/aspnetdb.mdf is still somewhat required :Z.
By the way, it seems like aspnetdb.mdf is only used for the roles. Unsure about that.
Alright I finally fixed it. I will write the solution incase anyone else is facing this problem or will in the future:
Try to add a aspnetdb.mdf from the internet and see if you face Error 26 of bad connection.
Uninstall the installed instance of Microsoft SQL Server in Control Panel -> Uninstall.
Download the installation from (http://www.microsoft.com/en-us/download/details.aspx?id=29062) and choose the version fitting your OS. (Mine is x64)
Install a server instance. Mine was SQLExpress previously.
Now enter the Administration tool and everything is like it was before.
The reason for this was closing the server through task manager. Not sure which one of the tasks was the one responsible for this, but, however - the best way is to re-install the server instance on the local machine.
I'm still looking for a way to have everything on the hosted database but I don't really care as this could be in the website's host..
The aspnetdb is for roles. If you want, like me, to have everything on the database server, learn about roleproviders (like membershipproviders) it just helped me get everything fixed.
Related
Note: This is different from Cant find my EF code first database
He didn't specify the initialCatalog while I did as you will see:
I have 3 CodeFirst DBs that I work with.
1 I create and use in my visual studio project when I hit F5
1 I host in Azure with test users. If I want to update it, I simply remove it and recreate it by publishing my VS project
1 that is somewhere in my localDB, hosting it in my IIS in my machine, which is my issue. I can't find it! I don't know where CodeFirst places it. But I can access the website which somewhat brings records from it! Please help me find it.
Here is my entire setup: in my publishing profile for the Local:
lets call the blacked out "ProjAPIContext"
and in my IIS
and the www root folder is simple. The AppData folder is always empty:
and I have this in my web.config
<connectionStrings>
<add name="ProjAPIContext" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=ProjAPIContext; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|ProjAPIContext.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
the context matches what is in code:
internal sealed class Configuration : DbMigrationsConfiguration<ProjAPI.Models.ProjAPIContext>
That's my setup. I am looking for the DB so I can navigated through table rows and run sql queries against it, etc...
I have looked my entire harddrive with that ProjAPIContext. I see other DB created with the same times frame like tempdb and masterdb but they can't be those.
I have attach the debugger to connect to my server code in my visual studio, but nothing hit. I've run the profiler in my sql, it doesn't print the connection string. It prints useless junk.
UPDATE #1:
I also looked here:
Update#2:
of course I've looked there:
Where else should I look!?
I am trying to set up a simple ASP.NET MVC 4 webapp using DB first migrations from a SQL Server (2005). I have created the tables in the database and used Entity Framework to create the objects in the code. I can access the data using these objects.
The problems come when I try to initialize the WebSecurity using WebSecurity.InitializeDatabaseConnection("FLMREntities", "UserProfile", "UserId", "UserName", true); in the Global.asax.cs file. I have tried using the InitializeSimpleMembershipAttribute filter that came with the template and got the same issue. I get the error message:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
Here is the relevant connection string:
<add name="FLMREntities"
connectionString="metadata=res://*/Models.FLMR.csdl|res://*/Models.FLMR.ssdl|res://*/Models.FLMR.msl;
provider=System.Data.SqlClient;
provider connection string="data source=notes.marietta.edu;
initial catalog=muskwater;
user id=muskwater;password=********;
MultipleActiveResultSets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
Also, I have created the membership tables in the database to match what the template creates. If I change the final parameter in the Initialize call to false (so that it does not try to create the tables automatically) it returns that it cannot find the UserProfile table. I have also tried variations on the names, such as [dbo].[UserProfile].
All I need is to have a simple account model to allow users to log in and allow certain users to see more content.
I had a similar problem, what I've done:
I modified the default connection. I already had a connection string for the edmx model, which looked like this:
<add name="ChemicalReporterEntities" connectionString="metadata=res://*/ChemicalDB.csdl|res://*/ChemicalDB.ssdl|res://*/ChemicalDB.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLExpress;initial catalog=ChemicalReporter;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
But I cannot used it with the SimpleMemebrship provider. So in Visual Studio I opened the Server Explorer > Data Connections, I selected my connection, right click, properties and I copied the connection string from there and pasted it to defaultConnection:
<add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;Initial Catalog=ChemicalReporter;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
After that I changed WebSecurity.InitializeDatabaseConnection to use the DefaultConnection.
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);
This could be a duplicate of this.
From what I remember about this problem, you need to make sure that the sqldata provider is registered. Sometimes, in your machine.config there is a duplicate entry that you need to delete and if I remember correctly, there could be an erroneous entry that you need to remove. Have a look at this msdn post, the info for this is about halfway down the page.
The link to the other SO has some links that could be helpful. If this ends up not being marked as a duplicate question, I can add them here as well or whatever is the proper thing to do.
The section you are looking for will look similar to this I think:
<system.data>
<DbProviderFactories>
<add name="SqlClient Data Provider"
invariant="System.Data.SqlClient"
description=".Net Framework Data Provider for SqlServer"
type="System.Data.SqlClient.SqlClientFactory, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</DbProviderFactories>
</system.data>
From the information you have provided in comments, it seems that this is missing in your machine.config. Unless I am mistaken (possible) that means that the SQL Provider isn't registered on your machine. You'll need to add the above section to your web.config. You'll also need to make sure that System.Data.SqlClient is referenced in your project.
If this isn't installed on your target machine, you'll have more work to do, getting it installed. I wish I could help you with that more, but when I did this, it was for SqlServerCE, so the files I used are much different.
Good luck!
EDIT:
A critical piece of information, is the version needs to match the file that you are using. in type="blabh..blah..blah..Version=2.0.0.0, blah blah" that needs to be the version of the file you are using so right click your file and get the file version. If it fails, try variations of the version. I believe my file was 2.0.0.1 but Version=2.0 is what worked when I did it. Just try a few different versions based on your version number (2.0, 2.0.0, 2.0.0.1 for example).
Just wanted to chime in here, that I had this issue, by looking at my machine.config for the targeted .NET version that I was running off of... within the structure:
ensure that your targeted data providers are correctly inputted within there, only one per provider (I have seen duplicates cause problems), as well as, ensure that it is valid XML, and you only have one DBProviderFactories entry. In my case, I had a entry after the initial entry (essentially two entries, one with my providers, one blank), and the blank was was causing all the issues.
Hope this helps someone with the same issue :)
This is a bit of a weird one. I'm doing an MVC 3 code first development using the SQL compact 4 stuff. Its all running fine but I'm getting issues when I try to scaffold a new controller. I fire up the new controller dialog and select my entity and the datacontext (both of which are in a separate assembly in the same solution) and get the following error:
Unable to retrieve metadata for 'MyNamespace.MyClassName'. Access to the database file is not allowed. [ 1884,File name=C:\Program Files\Microsoft Visual Studio 10.0\Common7\EntityContext.sdf,SeCreateFile ]
That file does not exist on disk at the moment - the EntityContext.sdf file is sat in my App_Data folder. I'm not sure if its trying to create that file (and if so why?) but if it is I'm not logged in as admin so it won't have permissions. In that case do I need to define a difference working folder or something?
I've tried it running as admin now and it works, so it's definitely trying to create a file in my Program Files directory, there must be a setting for temp files somewhere?
Any help would be great :)
Did you find an answer to the issue? I was having the same problem but handled it through the deployment transforms...
In Web.Config I used full path to the SDF:
<configuration>
<connectionStrings>
<add
name="DBContext"
connectionString="Data Source=C:\full-path\DBContext.sdf"
providerName="System.Data.SqlServerCe.4.0" />
...
In Web.Release.config I replace the connectionString attribute...
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add
name="DBContext"
connectionString="Data Source=\DBContext.sdf"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
After a release deploy the correct "|DataDirectory|" setting is made rather than "C:\full-path\".
I would like a fix to the original issue though!!
PK :-)
I have also faced the same problem when tried to export SQL CE db script with number of utils. Got error "Access to the database file is not allowed". Then I have just connected to that db-file from VS2010, copied connection string and... it worked! :)
I ran into this issue when using the T4Scaffolding. I got around the problem by installing the MVCScaffolding nuget package and used the "MVCScaffolding: Controller with read/write action and views, using EF data access code" template. It produces similar controller actions and views. I was unable to uninstall and reinstall the T4Scaffolding nuget package to see if this was a bug or corrupt install.
Has made the following guide: http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs
It automatically creates options for users to register and login. Where are they stored? Can not find it in the database. How do I check if someone is logged in?
It stores the information in a SQL Compact 4.0 database.
By default the ASP.NET MVC X Web Application project template uses the ASP.NET Membership Provider to store and manage the users which according to the article are stored in a SQL Compact 4.0 database. But if I recall correctly there isn't an officially supported membership provider for this database.
Sure you could write your own or use a third party solution such as:
http://sqlcemembership.codeplex.com/
However, if I download the code for the guide and check out the Web.config I notice that the SqlMembershipProvider is used and this is linked to the connection string called "ApplicationServices".
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
... />
Let's take a look at that connection string:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
Apparently its stored in a local database file called "aspnetdb.mdf" which is probably located in your web application's App_Data folder.
That is where you can find the user data. But is it actually used in this guide? Appears not, might just be a remnant of the default ASP.NET MVC Web Application project template.
The movie-related data is stored in an SQL Compact 4.0 database. A different connection string is used for it.
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
Also a local database file, but this time it is a different provider (SqlServerCe.4.0. instead of SqlClient).
I'm trying to use EF Code First with my WPF application , the idea is to create a SqlCe Db in AppData/MyApp (if there isn't one) and use it with EF Code First.
At the moment it's giving error when I try to read data off the database it supposed to create , but when I checked the db context object I saw it's trying to create it in SqlExpress.
First of all , how can I set it to work with CE instead of SqlExpress and set the file location?
I tried changing the connection string in app.config but couldn't get it to work (it didn't created sdf file) and also I'm not sure how to set connection string path to AppData folder as it's in User folder (not fixed).
Never worked with SqlCe or EF Code First before , so any help is welcome & appreciated.
Thanks in advance.
I've managed to get it working after a lot of messing around. My app.config has the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Database"
connectionString="Data Source=Database.sdf"
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0"
invariant="System.Data.SqlServerCe.4.0"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
</configuration>
Having the DbProviderFactory in there will help when it comes to deployment too. It will allow users to use SQLCE 4 without running the installer for it (providing you supply the native binares as well, some info here: http://erikej.blogspot.com/2011/02/using-sql-server-compact-40-with.html).
Here is a possible clue. If you were to install EFCodeFirst.SqlServerCompact using NuGet Package manager, and look in: Visual Studio 2010\Projects\MyProject\packages\EFCodeFirst.SqlServerCompact.0.8.8482\Content, it does things for your web app like:
public static class AppStart_SQLCEEntityFramework {
public static void Start() {
DbDatabase.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
// Sets the default database initialization code for working with Sql Server Compact databases
// Uncomment this line and replace CONTEXT_NAME with the name of your DbContext if you are
// using your DbContext to create and manage your database
//DbDatabase.SetInitializer(new CreateCeDatabaseIfNotExists<CONTEXT_NAME>());
}
}
I don't think the tooling is ready for SQLCE for WPF projects. It stopped me in my tracks too.
This probably isn't going to help in the short run, but I think it would be the best solution in the long term. I haven't been able to find where anyone else has documented how to do this so I guess I'll have to figure it out as I go unless someone with more intimate knowledge of using SqlCE4, CodeFirst, and creating NuGet packages beats me to it. What we need is a NuGet package, either a new package or make the existing one smart enough to handle it, that can add SqlCE4 and CodeFirst to a WPF and/or WinForms project.
The existing package seems geared toward web projects since it depends on WebActivator. From what I can tell, installing WebActivator on a non-web project really isn't appropriate. I don't know if it's possible for a NuGet package to detect the project type and execute different installation logic based on that information. It would be better all around for whoever is responsible for maintaining the EFCodeFirst.SqlServerCompact package to either release a non-web version or make the existing one smarter.
Pending that, in my spare time I'm going to see if I can figure out how to do it and create my own. I can't promise how long it'll take me because I'm almost totally in the dark with regards to creating NuGet packages. I've created a couple of really basic ones but have never done any advanced stuff like config transforms and the like.