I am trying to change the place my webform saves the data.
What I mean is, when you open a Visual Stuido/C# Web App, its has a user login/register data.
The default data is saved in your project folder, in APP_DATA as: ASPNETDB.MDF.
What about if I want to use MSSQL Server 2008R2.
How can I change it?
Just setup a new database and change your connectionstring in the web.config:
Using SQL Server instead of ASPNETDB.mdf
<connectionStrings>
<add
name="NorthwindConnectionString"
connectionString="Data Source=serverName;Initial
Catalog=Northwind;Persist Security Info=True;User
ID=userName;Password=password"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
How to: Read Connection Strings from the Web.config File
in really server MS Server 2008R2 you must doing backup from your "home" datafiles: "in APP_DATA as :ASPNETDB.MDF"
p.s. sorry for my bad English.
Related
I have created an instance of ASP.NET Web Forms in my Microsoft Visual Studio. By default the program generates user login page and registration which are linked to the .mdb file.
I want to reconfigure the standard connection and link it to my instance of MSSQL 2012 SQLExpress server.
How can I do it?
Ok so I will give some direction and link you to a page.
First let me ask you this the connection you are using presently is it in a web.config file. If so this is where you will change the server/instance and database/catalog name.
Web.Config modification for SQL Server Instance
or this link
Web Config modification for SQL Express 2
So if you in the web.config file you should see something similar to this.
<ConnectionStrings>
<add name="" connectionString="Server=(localhost)\SqlExpress;Max Pool Size=300;Initial Catalog=database;User ID=username;Password=password;" providerName="System.Data.SqlClient"/>
</Connectionstrings>
or
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source= (LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\database.mdf;Initial Catalog=database;Integrated Security=True" providerName="System.Data.SqlClient" />
you need to change the follow:
Server or Data Source
and
Initial Catalog or AttachDbFilename
Now your credentials you may use any username and password that has access to the sql server express instance.
I hope this helps.
So if I create a new MVC project with basic log in template, there should be somewhere a database which contains all the user login information. There's even the default connection string which points to it.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MyProjectName-20140521042155.mdf;Initial Catalog=aspnet-MyProjectName-20140521042155;Integrated Security=True" providerName="System.Data.SqlClient" />
How ever, when exploring the project folder I cannot find it. I also tried to turn on "show all files" option in the solution explorer.
Sql Server Management Studio can be used to connect to the local db server. You can also use visual studio server explorer.
I added a new Sql Server Database to my project with the name: ShDB.mdf. It is located in a App_Data folder.
It contains a Table which has some columns. I could add some numbers to the table and then show them in a gridview on my localhost.
This is what I have in the web.config:
`<configuration>
<connectionStrings>
<add name="ShConnectionStr" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Javad\Desktop\Sharj\App_Data\ShDB.mdf;Integrated Security=True;User Instance=True"/>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ShDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
</system.web>
`
Here is the vb.net code which I used:
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ShConnectionStr").ConnectionString
And it works properly on the localhost test but when I published the website and uploaded the files on a web hosting service to test, I counter an error. How may I fix it? I think I should change my Data source path but I don't know how because its my first experience. Thanks to any help. you can see the error page here: http://www.kaj.somee.com/SL.aspx
Sql Server is either not installed or not running on the web host, or you don't have access to connect to it.
ASP.Net does not by itself know how to use your *.mdf database. It needs a running instance of Sql Server to talk to. It will tell Sql Server to load (attach) your database file, and then send queries to the Sql Server service for execution.
Do you mean you already uploaded the website to a web hosting service, but not the database?
If so, your application may not communicate directly with your database which is actually in your local machine.
You probably need to upload the database to a database hosting service as well (eg.SQL Azure, etc).
You may need to figure out the IP address/Server Name of your database hosting where you have uploaded. These information you can probably get in for the service provider. From there you should be able to connect to the database with the correct configuration.
i have a problem with the asp.net MVC3.
when i create a new project and start the asp.net configuration my browser opens and i can edit e.g. the user.
but when i change the connection string to my external server or to my local sqlexpress server, i get the message after the browser pops up:
The type "MyApp.MvcApplication" could not be loaded.
what do i wrong? my connection string looks like:
<add name="ApplicationServices"
connectionString="Data Source=my-pc\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
Looks like the type hasn't actually been built and packaged as a DLL into the bin folder. Did you try running the project initially before making the change?
User registration/authentication seems to be built into MVC2 but where does is the database that stores the users? It's not under data connections.
The default template uses SQL Express edition. An aspnetdb.mdf file will be stored in the App_Data directory. Look at the connection string in web.config:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
u don't have to use aspnet_regsql.exe tool - just start your app, register new user, and then open the app_data directory in windows explorer - u will find your db file over there
Arek
The database is first created when you create the first user for the website. After that the .mdf file is in app_data folder.
If you want it to be shown in VS, you can click Project -> Show all files and then it should be visible in Solution Explorer. Right click ASPNETDB.MDF and click Include in project.
App_Data folder