Sorry for the noob question. Someone has insisted me that it is possible to connect the .bak file to the asp.net website by just using connection string in the web.config only. However, I am in the midst of confusion because it doesn't make any sense to me because the .bak file is the backup file for the SQL Server.
My real question is, is it possible to connect it without dealing with SQL Server? What are the alternatives and suggestion you have?
Here's the example of web.config file he shown to me.....
<add name="accountConnection"
connectionString="Data Source=\data\websiteXl.bak; Initial Catalog=websiteXl;Integrated Security=True"
providerName="System.Data.SqlClient"/>
I have tried alternatives like using .mdf too....
<add name="accountConnection"
connectionString="Data Source=\data\websiteXl.mdf; Initial Catalog=websiteXl;Integrated Security=True"
providerName="System.Data.SqlClient"/>
This is utter crap - you cannot just connect to a .bak file, you're right (and that "someone" is plain wrong).
You will need to restore that .bak file onto a SQL Server instance, and after that's done, THEN you can use that database
No, that isn't possible. The backup file generated by SQL Server (usually with a .BAK file extension) is a compressed backup file that's not directly usable, generally.
The only thing you can really do with it is to restore the database, or make a copy of that "snapshot" of the database on another server, or the like.
There are some tools (like Red-Gate's SQL Compare and SQL Data Compare) which can show you the differences between a backup file and a live database, or between two backup files. But, that wouldn't help you connect to it through an ASP.NET page.
Related
I have created a database and a simple web form with couple of text-filled and a submit button in visual studio 2019(Asp.net c#). now I'm trying to save user data into the tables, since I'm not using sql server management do I still need use SqlConnection if so what is the best way to create a connecting string?
The best way to create a connection string is to write it in the Web.Config file which you will find it at the bottom of your Project in Solution Explorer.
Web.config file is basically an xml file that contains the configuration of your websites which includes your connection string.
<connectionStrings>
<add name="YourConnectionStringNameHere" connectionString="Data Source= DatabaseServerName; Integrated Security=true;Initial Catalog= YourDatabaseName; uid=YourUsernamehere; Password=Yourpasswordhere; " providerName="System.Data.SqlClient" />
</connectionStrings>
Why to write the connection string in Web.config?
You don't have to declare the connection string again and again and again in each .cs file. This is tedious. You will have one connection string at one safe place.
This is required because if some other guy handles your project and wants to change the connection name according to the requirement (in future) then it would serve a sole area as the developer don't have hassles here and there to find your connection string. This provides a clean code to understand not only you but also to other developers who will be handling your projects in future.
The SQL connection would still be required:
The SQLConnection would be required in order to connect to the database no matter whether you use SSMS or not. Even in the internal database that Visual Studio provides, you will be required to provide this connection string reference in your .cs file.
Hope this helps.
In my web.config file, I have a connection string to connect my development database.
<connectionStrings>
<add name="MembershipDB" connectionString="Data Source=DebugSQL;Initial Catalog=PortalAccess;Integrated Security=True;Application" providerName="System.Data.SqlClient"/>
When I publish the web site to my production server, I just change the Data Source name.
When I test it, then I switch it again, is it stupid?
This is quite a common approach and can work well.
Obviously you can run into problems if you get the details wrong while maintaining it by hand this way.
You could also have a look into web.config transformations: This is a way of writing a main web.config file and then writing separate files that change the original depending on the build configuration you run.
Some resources:
Related question on StackOverflow;
Asp.Net tutorial;
MSDN Video for VS 2010.
I have made a MVC application that uses the built-in ASP.NET login functions. It works perfectly on my local machine. I have bought a webhosting service, because i want to publish my website to the internet.
How do i copy the membership and role database / tables to my new MS SQL Database and make it work with my current project?
In my Web.config i have:
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
notice that
Instance=true
This means that SQL Server Express will open the aspnetdb.mdf file, creating it on the fly first if needed.
When i try to login on my website i get the following error:
Sorry, an error occurred while processing your request.
Thanks
You need to run aspnet_regsql located in C:\Windows\Microsoft.NET\Framework\v4.0.30319. Just point it to your remote sql server and it should take care of the rest.
You will also need to edit your connection string for application services to the one for your remote sql server.
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.
I am creating a package of an asp.net mvc3 application to distribute it. Means I want to zip it and send it to someone for review. I want that you just start the solution in VS and it runs. So no need for changes in web.config.
I was using sql server with hard-coded DataSource. (COMPUTERNAME\SQLEXPRESS)
I changed it to .\SQLEXPRESS to make it relativ. Better.
Then i detached the db with SSMS, copied the DB to the App_Data folder, added AttachDBFilename=|DataDirectory|MyDatabase.mdf;
And (as found on msdn) Initial Catalog=; "use it but don't set it"->great feature ;)
This is the result:
<connectionStrings>
<add name="DBService" connectionString="Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|MyDataBaseFile.mdf;Initial Catalog=;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
When I start the asp.net Development Server (hit "play") in VS Web Developer 2010 there is a Database error:
Unable to open the physical file ".........mdf". Operating system error 5: "5(Zugriff verweigert)".
Any suggestions how to attach the file to the solution? What about switching to Compact Edition?
Have you tried adding
User Instance=True
?
Data Source=.\SQLEXPRESS;AttachDbFilename="|DataDirectory|MyDataBaseFile.mdf";Integrated Security=True;User Instance=True