ASP.NET Membership mdf to SQL Server - sql-server

I had membership working fine locally. But now need to deploy so created membership tables / stored procedures using the Aspnet_regsql.exe and changed my web.config to point local sqlexpress database instance.
My membership is still working but not using SQL Server. I went and deleted the .mdf file that my connection string was referring to earlier from the APP_DATA folder. My form authentication is still working allowing me to register new users but not using SQL Server!
What is it using?
<remove name="DefaultConnection"/>
<add name="DefaultConnection"
connectionString="server=PC\SQLEXPRESS;Trusted_Connection=true;database=adatabase;"/>
My connection string looks like above. I have one more connection string below this whose value is exactly like this for now, just FYI. All the membership sections like DefaultMembershipProvider use DefaultConnection connection string.

I was looking at this table called dbo.aspnet_Users all this time. There is another table down below called dbo.Users and that is where users are getting created. So IT IS using SQL Server! The Aspnet_regsql.exe tool installed these aspnet_* tables. And it looks like the actual table where users are created is getting created afterwards. I got that from these tables' time stamps - they are over 20 mins apart.

Related

Azure SQL and Visio 2019 Plan 2 Database Reverse engineering wizard Fails

Screenshot of ErrorI am using Visio 2019, trying to reverse engineer a Azure SQL server. I have successfully created multiple User data sources to use in the wizard using both our DB-admin user and my admin azure directory logins. The database credentials are successfully verified and the tables/views i want to reverse engineer are about to load in when i get the following:
Visio reverse engineer database wizard raises error:
"Error! Cannot extract column definition for the table/view . The definition is not
available or you may not have sufficient privileges."
with a text box that says:
"Could not find server "database name"* in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers."
I can neither find sys.servers nor run sp.addlinkedserver as it does not exist. though, sys.sysservers does exist.
I starred database name since instead of showing the target DB of "DB_2.0" it shows "DB_2" which is not the full name of the Database.
As i mentioned above i believe that i have sufficient privileges as i have tried both the admin username and password and my admin login using azure directory. So it may have something to do with not having the sys.servers table?
Is there a way to create the sys.servers table or create the stored procedure sp.addlinkedserver as Visio is requesting? Is it advisable to do is Azure SQL, could the naming convention of our DB have anything to do with the error?
Worked with MSFT support, they had me rename my database from DB_2.0 to DB_2. I created a new connection DSN and it worked perfectly afterwards. Apparently visio doesn't like the ".0" in a connection string. It would be nice if i could have eddited the connection string in a text file so I did not have to rename my entire DB.

Renaming SQL Server database and MVC5

For reasons not worth going into, I had to rename a Microsoft SQL Server database that an ASP.NET MVC project was using. I thought that, on the MVC side, this would be something as trivial as changing the connection string in the web.config. Alas, no.
The database name went from myproject.MODELS.OSESDBCONTEXT to myproject.
So, I changed the default connection block in the web.config to reflect that, all else being equal:
<defaultConnectionFactory
type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=machine.company.com;Initial Catalog=MyProject;User ID=someuser; Password=somepassword#;MultipleActiveResultSets=False" />
</parameters>
</defaultConnectionFactory>
It seems to be failing to connect to the database, but since it can't find the database it is attempting to create a new one but it fails because the .mdf file is already present. However this isn't the issue, it should be connecting to SQL Server.
This is the error I get when running the web page:
Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyProject.Models.OSesDBContext.mdf' because it already exists. Change the file path or the file name, and retry the operation.
You might be able to accomplish what you're after by doing a database attachment.
Can you try to reattach it via SQL Server Management Studio or through T-SQL?
First, copy your mdf and ldf files to something new (name them relative to a new database you'll attach them as).
Then in the Attach Databases screen:
Enter your new name for the database in the Attach As field in the top frame
In the bottom frame, browse to both the new mdf file and the new ldf file you just created.
You should then have a newly attached database.
I don't think database name should be specified in defaultConnectionFactory - it seems like it's about server in the first place.
Database name should be specified elsewhere, e.g. see the possible options here https://msdn.microsoft.com/en-us/data/jj592674.
I can only suspect the old database name is still somewhere in the places mentioned above. Have you tried to search for the old name in the sources?

Is it possible to convert a sdf umbraco database to Azure SQL?

I have a project that uses a local database(SDF) for umbraco which is hosted on azure, I would like to copy the data from that local database to a new one that will be hosted on Azure sql, then I want to update connection string to use that database, is it possible ? Or I will need to redo the website from scratch.
I've tried searching for the answer but I can't seem to find the answer.
I have downloaded the website using webmatrix, but the database doesn't download with the whole project :/
Yes, If you use this exporter you can generate a script of the database:
http://exportsqlce.codeplex.com/releases/view/116839
ExportSqlCe40.exe "Data Source=Umbraco.sdf;" export.sql sqlite
Initializing....
Generating the tables....
Generating the data....
Generating the indexes....
Sent script to output file(s) : export.sql in 760 ms
You must then add an extra line to add an index on the logins table
CREATE CLUSTERED INDEX umbracoUserLogins_Index ON umbracoUserLogins (contextID);
The issues I had were that the order of the records generated for the umbracoNode table. You must ensure the item with key -1 is inserted first and that it did not mark identity columns which I had to do manually.
Once you have ran this on an azure sql server instance, change your connection string ensuring you update the provider string to System.Data.SqlClient
<add name="umbracoDbDSN" providerName="System.Data.SqlClient" connectionString="[azureconnectionstring]" />
In the end i created a new umbraco project using webmatrix, created a new template site with an sql database and executed the sql query from the old sdf. database in that database, then I migrated it to azure with few modifications regarding clustered keys and it worked

Sql Server keep old references to deleted databases

I have an ASP.NET MVC solution with a DB named LearningDB.
Here is my connectionstring in my web.config
<add name="EntityFrameworkDbContext"
connectionString="Data Source=.\SQL2008;Integrated Security=SSPI;Initial Catalog=LearningDB;MultipleActiveResultSets=True;User Instance=true"
providerName="System.Data.SqlClient"/>
My Sql Server is named SQL2008 and is a full SQL SERVER (not the express one).
Strange thing: when I run my solution, it successfully created the DB and allows me to add data to this DB. I didn't use the AttachDBFilename attribute (to specify where to store the DB) so the DB is located under C:\Users\Thierry\AppData\Local\Microsoft\Microsoft SQL Server Data\SQL2008
I already query the sys.databases to list my table but I only have 4 tables (master, tempdb, model, msdb). I would like to delete these corrupted references to deleted databases but I don't know where!
Any idea?
Thanks.
EDIT
As Mikael suggest me, I edit my question to be clear: I didn't want to delete master tables, etc...
Le'ts take an example: I have a DB named LearningDB.mdf in my asp.net mvc solution. I deleted physically this DB (with Windows Explorer, I know this is not the best thing to do). Next, when I restart my solution and run it, the system try to recreate the DB and warn me that the name LearningDB is already exist!! How this can be?? I already check in SQL SERVER with Management Studio but didn't found anything!

problems with automatic creation of the database in EF4

I'm learning ASP.NET MVC 3 with Entity Framework Code First. I'm following a tutorial and I downloaded the corresponding solution for testing on my local machine. Now, something I didn't understand very well is about the automatic creation of the database (if this one didn't exist yet on disk). The very first time I run the application, the database is created for me. That's ok.
Here is the section in Web.config
<add name="BlogContext"
connectionString="Data Source=.\SQL2008;Initial Catalog=CodeFirstMVC.mdf;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
But I have two problems:
1st. For testing purpose, I deleted the database on disk and run again the solution. I thought that the database would be automatically created but I was wrong: I got the error message below:
{"Unable to open the physical file \"c:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQL2008\\MSSQL\\DATA\\CodeFirstMVC.mdf.mdf\". Operating system error 2: \"2(failed to retrieve text for this error. Reason: 15105)\".\r\nCannot open database \"CodeFirstMVC.mdf\" requested by the login. The login failed.\r\nLogin failed for user 'sa'.\r\nFile activation failure. The physical file name \"c:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQL2008\\MSSQL\\DATA\\CodeFirstMVC.mdf_log.LDF\" may be incorrect."}
I noticed that if I changed the file name in my Web.config then the database is again successfully created. Can you explain me? Why do I have to change the database name to get it running again?
2nd. The database is created in the folder located in C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA. I would like to store my database in the App_Data directory. How can I proceed?
Initial catalog is not path to file. It is the name of database. AttachDbFilename is used to specify the file so your connection string should look like:
Data Source=.\SQL2008;Initial Catalog=CodeFirstMVC;AttachDbFilename=|DataDirectory|CodeFirstMVC.mdf;Integrated Security=SSPI
Where |DataDirectory| instructs SQL server to use local application data directory instead of global SQL Server data directory. Local data directory for web application is App_Data.
Edit:
I just noticed that you are probably using full SQL server instead of SQL server express. As I know creating database in App_Data automatically is feature of SQL server express. That also explains first error because SQL server created database called CodeFirstMVC.mdf and stored the database in its global data directory within CodeFirstMVC.mdf.mdf file and transaction log in CodeFirstMVC.mdf.ldf file. It also registered that database internally. By deleting files you didn't remove database from SQL server. You just break its functionality but SQL server still believes that the database exists. That is also reason why you have to change the name to make it work.

Resources