How Can I upload ASPNETDB Database to Server? - asp.net

I have uploaded my database backup and it works fine. but since I've created a new user from ASP.NET Configuration I've that it saves the user information in the ASPNETDB.
I already published my database from MVS and open it in M SQL Server Management Studio 2008 to create the backup but I haven't find the ASPNETDB in it.
my question is:
doesn't this database just upload it automatically when I upload my database? coz when I publish my website it doesn't appear.
if not, How can I upload ASPNETDB so I can login to my site because I'm using authorization to this user ?

Ok im gonna make a few assumptions here and explain them because this could be many things:
Assumption 1 (connection string issue). the user credentials for a database running on your local sql server are likely to be valid on the server on which you deploy to (seems to be the way of the world) try connecting to the remote database using the credentials in the remote "published" copy of the websites configuration file. (connection string)
Assumption 2 (publish settings not correct). when you use the "publish" option from within visual studio you only deploy the website to my knowledge but some say you can configure it to deploy the database as well.
I would suggest making a change (eg add a table to the aspnet database) on your dev machine then using publish to see if that new table appears on the remote server, if it doesn't go to the server explorer in visual studio and run the wizard by right clicking on your database and clicking on "publish to provider" i tend to push the entire db to a script file then manually run that on the remote database (seems the cleanest option).
Assumption 3 (does the database even exist on the server). I could be wrong here but from what you're saying it sounds like you published the application and not the database to the server ... that results in some nice yellow server errors.
Check that the database exists if not ... do as suggested in asumption 2 and push the database manually.

I suppose you're using the Membership API.
If you are using ASP.NET on a machine with SQL Server Express Edition, the required by Membership API underlying data store is created automatically for you when you create the first user. This functionality is provided through the SqlMembershipProvider. The SqlMembershipProvider automatically creates a new database in the website’s App_Data special directory called ASPNETDB.MDB. This database implements the complete schema, which is necessary for storing and managing user information, role information, user-role assignments etc.
You can easily check it. In your web.config you should see something like:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
So this database should have been uploaded along with your web site.
Please consider this tutorial if you want to create aspnetdb or necessary tables in your own database (which is a good praxis).
May be you will be also interested in the similar discussion here. Besides if you still want to get this .mdf database in SQL Server Management Studio you can learn how to attach a database here.

Related

How to Connect Kentico Website with database

I just started working with Kentico and after Kentico Installation there is no setup files for my sql server database but I get the files are locally stored in the database(on localdb). So now I want to know that how can I connect with the existing database(sql server). As I try to change the web config but there are issue when we run the service from Kentico Service Manager.
Also I am having an another issue that how can this be possible with kentico that if the admin made certain changes in the text through interface and those changes should be reflected in database as well.So that next time when anybody tries to access the website it will reflect to him. Please let me know about it. Thanks in advance.
Please, refer:
Connecting your project to the database
Daabase Setup
Managed projects are connected to the database and contain Kentico EMS data by default.
If you're using an unmanaged project, you must connect the project to the database manually. You have two options to connect your project to the database:
entering the database credentials into the database setup wizard
adding a connection string to your application's web.config
Connection string template
<add name="CMSConnectionString" connectionString="Persist Security
Info=False;database=DATABASE_NAME;server=SERVER_NAME;user
id=USER_NAME;password=PASSWORD;Current Language=English;Connection Timeout=240;"/>

Azure site only works when running locally with remote database

I have a site that's running off windows azure and I have hooked up the database via a linked resource and it looks like the site should be using the database. I've also included the proper connection string in my web.config file.
When I run the website locally and use the azure database's connection string for my default connection, everything works and I've seen that updating data from my local machine is reflected in the remote database.
Whenever I try to access any page that makes database hits (ie, logging in or looking at the basic index (from scaffolded out views)), I get a 500 error. I tried turning on custom errors but the 500 error is all I get. I tried to debug it from my local machine but that didn't help at all since everything worked properly when running the site locally and connecting with the azure database.
I have also pulled down the web.config files and the web.configs on both sides are identical.
I figure that this has to do with a configuration issue, but I'm not sure what.
Is there maybe something I'd have to do with asp.net mvc 5 to make it work with windows azure? It looks like the .net framework is properly set on azure to .net 4.5. I'm guessing it has something to do with the fact that Azure just doesn't know it should be using the database supplied in the web.config.
Here are the web.config connection strings:
<add name="DefaultConnection" connectionString="Data Source=####.database.windows.net,1433;Initial Catalog=####_db;Persist Security Info=True;User ID=####;Password=####" providerName="System.Data.SqlClient" />
<add name="DefaultConnectionDeploy" connectionString="Data Source=####.database.windows.net;Initial Catalog=####_db;Persist Security Info=True;User ID=####;Password=####" providerName="System.Data.SqlClient" />
<add name="DefaultConnection_DatabasePublish" connectionString="Data Source=####.database.windows.net,1433;Initial Catalog=####_db;Persist Security Info=True;User ID=####;Password=####" providerName="System.Data.SqlClient" />
Windows Azure makes use of transforms to manage connection strings. The connection strings are merged in at runtime, and can be controlled from the configure tab on the Web Site management page. whenever you set up an Azure Database as a linked resource, it automatically configures the Azure Database server with firewall rules to allow connection from the web server, and adds a connection string. By using this connection string, naming it the same as the string used in development, it is not necessary to modify any code prior to deployment. If you don't set the Azure Database up as a linked resource, it is necessary to modify the firewall rules by hand, which doesn't play nicely with the scalability of Azure Websites, so it's not recommended.
As per Andrew-counts' suggestion, I went and checked out my EF migrations (after pulling down the Azure web.config file using the "Replace web.config from server" option so that I had the exact copy that the server is using. I then enabled custom errors. It turns out that the pages were failing to load because of an error that stated that the table dbo.AspNetRoles already exists.
It appeared as though it was trying to run the EF migrations despite the fact that the tables already existed. To remedy this, I decided to go and wipe out my current database (I had just setup the database today so no harm doing that) and then, from the package console in visual studio, ran the Update-Database script before deploying anything to the server. When I did that, it correctly added the records inside of the dbo.__MigrationHistory table. I then checked in my changes so that the visualstudio.com build I have connected to my solution would build and deploy to Azure. The problem persisted, but what I realized was that I need to disable the automatic build + deploy that I was using and instead use the right click + publish, since doing it from the visual studio build wasn't connecting to the azure database properly (it wasn't transforming the web.config). When I used the publish from within visual studio, the site worked like a charm.
Thank you for all your help

asp.net/sql server/iis permissions

I'm developing an ASP.NET web app that needs to access an SQL Server database. The server the app needs to run on is running Windows Server 2000, SQL server 2000, IIS6, and .NET 2.0.
If I run the web app on my machine with Visual Web Developer 2010 with the testing webserver in Visual studio, but accessing the database on the actual web server, it works fine. However, If I put this app on the actual webserver, and try to access it through the browser, I get a permissions errors saying I don't have access to those tables.
There are two tables my app needs to access. On one of them I changed the permissions with SQL Management Studio to allow the public group select permissions, and that solved the problem. On the other table (very large table) I tried to do the same, but got an error saying it timed out waiting to get a lock on the table. Is there a way to change this timeout or another way to change the permissions?
I don't believe I should even have to change the permissions though, because there are classic ASP apps on that server that access the very same tables. I think the issue is the user that is being used to access the tables. If I can access the tables running the web app from my machine, and classic ASP apps on the server can access them, but my ASP.NET app can't, my ASP.NET app must be using a different user account. How can I check this and make the necessary changes?
Regarding your permission error, it's probably because on your machine the app is accessing the database with your permissions, with windows integrated login.
Normally, a web application is supposed to access a database using a technical user, that is specified in the web.config file, in the connection strings section. It's something like
<configuration>
<connectionStrings>
<add name="myConnsStr" connectionString="server=myserver.example.com;database=mydatabase;uid=tech_account;pwd=tech_account_password" providerName="System.Data.SqlClient" />
</connectionStrings>
...
</configuration>
How does yours look like?
For the other one, yes, do the permission change in T-SQL. If you are not sure how to do that, do the change in the designer, then before clicking OK, use the Script button in the header area. Script the change to the clipboard and then try to run in a new query window. You can play with the query timeouts in the options dialog.
You could try setting the lock timeout to -1 (meaning it'll never timeout)
SET LOCK_TIMEOUT -1
GO
And you can also try adding the permissions using a query
sp_addrolemember #rolename = 'db_datareader', #membername = 'YourAspApp'
You can also try to change your asp.net user in the asp.net connection string to a user which already has selecting privileges.
Let me know if any of that worked, it's a good place to start with =)

Connection string setting while deployment

I have ASP.NET project and attached mdf database.I want to deploy it to remote server.I have just ftp account.The project works well on my local but ı had problem while deploying.I changed my connection string like. Please help me what is the problem ?
<add name="libraryConnectionString"
connectionString=" Server =.\SQLExpress;
AttachDbFilename= myusername#ftp.myserver.com/App_Data/LIBRARY.mdf;
Integrated Security=SSPI;
User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
You have to create a Ms-Sql server database (remote) along with user via control panel or you may ask to your hosting provider to create a database and user. Once database is created then you may execute your script (You may use Visual Studio Database Publishing wizard) and construct a new connection string for your web-app.
Have a look at MSDN article - Deploying a Database by Using the Database Publishing Wizard
The Database Publishing Wizard in Visual Studio enables you to deploy
a SQL Server database (both schema and data) to a hosting environment.
You can run the wizard by right-clicking a database in Server Explorer
and then clicking Publish to provider.

How do I change my asp.net membership database from express to standard sql?

I am building an ASP.NET 3.5 (C#) application and I plan to use the membership and roles security.
I want to set this up on my SQL Server 2008 standard edition and not the default express setting.
How would I go about this?
You can install membership database with this command
aspnet_regsql.exe
at *C:\Windows\Microsoft.NET\Framework\v2.0.50727* (adjust to your path)
You can find more details here
It doesn't matter wich database server version you are using for the ASP.NET security membership/role module, apart from being SQL Server.
To set up manually this security on a server you have to run these scripts:
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallCommon.sql
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallMembership.sql
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallRoles.sql
and configure web.config accordingly (see http://msdn.microsoft.com/en-us/library/6e9y4s5t.aspx).
You may run this scripts using the same database where you have your data, or you can create a new database to store user membership or role related data and run them there.
you need to run aspnet_regsql. That will popup the wizard to configure your new database.
Take the MDF and LDF files created by Express Edition (usually in App_Data) and Attach them to your SQL Server 2008 Instance.
Setup security for the new database (i.e. add a user to the database that will access the database. Make sure to give the appropriate permissions to the user)
Change the connection string in your web.config to point to the new database
Edit: My answer assumes that you're already using your database and just want to migrate it from SQL Express to SQL Standard edition.

Resources