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.
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.
I have a code first web.api project that was working fine with the automatically created .mdf in the App_Data folder. I decided to move my app to IIS and modify the app pool config to load the user profile, again, no problem. Then I loaded the .mdf in visual studios sql explorer and at that point, the app pool login from the web app started failing. No clue why and couldn't fix it, so I decided to use sql express instead of waste more time on it. So, I installed SQL Express, killed all my migrations, and modified the web.config connection string to:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=SSPI"/>
</connectionStrings>
When I try to use migrations to update-database or run the api app, I get an exception saying
Cannot attach the file
'C:\Users\Source\MyApp\Main\Solution\MyApp.API\App_Data\MyApp.DataService.DataModel.AppEntities.mdf'
as database 'MyApp.DataService.DataModel.AppEntities'.
Well, that makes sense since I deleted it, but why is my app still trying to connect to the .mdf file? It's gone and I've changed the default connection. I've searched the solution for anything referencing the .mdf file, but nothing shows up. What am I missing?
I finally figured out that I had to name my connection string the same as my DbContext class, so in my case:
<connectionStrings>
<add name="AppEntities" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=SSPI"/>
</connectionStrings>
to match my DbContext derived class
namespace MyApp.DataService.DataModel
{
internal class AppEntities : DbContext
I am a new developer and this is my first time to deal with two IIS servers. My company has two servers; Production Server and Testing Server. They are using the testing server for storing /hosting the databases and the Production Server for hosting the applications. All the applications are developed in ASP.NET. Now, for the web-based application that I am developing; I have to put the database in the Testing Server and the application in the Production Server,
so how can I reference the database in the web.config file?
What I have in my web.config file now is the following:
<connectionStrings>
<add name="testConnectionString" connectionString="Data Source=localhost\sqlexpress;Initial Catalog=psspTest;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
I have that because the database resides in the same server with the application. Therefore, how will I be able to reference when I put it in the Testing Server?
Let's say your testing server is called testsrv and the database resides on the
SQL Server Express instance, you simply change your config to:
<connectionStrings>
<add name="testConnectionString"
connectionString="Data Source=testsrv\sqlexpress;Initial Catalog=psspTest;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
I'm trying to deploy an asp.net application to a server using a SQL Server instance for the ApplicationServices membership database.
The problem is, I'm getting an error that says
The connection string specifies a local Sql Server Express instance
using a database location within the applications App_Data directory
I got this error when I initially tried to deploy the aspnetdb.mdf itself with the application.
I got this error when I then scrapped that plan and decided to do a web.config transform so that in Debug I use the Express database, but on Release the connection string goes to SQL Server.
I got this error again when I decided out of curiosity to remove all references to the express database from the code, so there could be no possible way anything would be looking for the Express database. No luck.
Does anyone have any ideas about this? I have deleted and re-installed the web site in IIS each time, noting that there is no App_Data being deployed and no mention of the .mdf file in web.config - to no avail. It still thinks there's a connection string telling it to look for a SQL Server Express database :/
Edit: Here's the connection string I'm using. Pretty standard, I think, but I could always be wrong.
Data source=HERP;Initial Catalog=DERP;Integrated Security=True
Could the error refer to the default connection string from the machine.config file (the LocalSqlServer one)? This could be happening, considering that the default membership provider uses this connection string:
The following default membership element is configured in the
Machine.config file [...]:
<membership>
<providers>
<add name="AspNetSqlMembershipProvider" [...]
connectionStringName="LocalSqlServer" [...]
Do not forget to clear the connectionStrings first:
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
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.