Asp.Net Default aspnetdb.mdf - asp.net

When you create a new ASP.NET project with membership it creates the default connection string for ApplicationServices as follows:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
Is there a way to force this to use SqlServerCe in the App_Data folder instead of creating it in sql express?

no its not possible, but you can check it via code for data source..

Related

Setting Up Connection String of Visual Studio Built in SQL file to ASP.Net?

I added database file to my built in sql server of Visual Studio and i have also connection string of it but i am confuse how to add this connection string into web.config
here is my try to add connection string to code below :
<connectionStrings>
<add name="myFirstConnectionString" connectionString="Data Source= .\SQLEXPRESS;AttachDbFilename="C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf"; Integrated Security=True;Connect Timeout=30;User Instance=TrueproviderName="System.Data.SqlClient" />
</connectionStrings>
I am much confused that how i can add connection string of my visual studio built in database file to web.config.
Please help me as i am new in asp.net and ignore my way of asking.
To make your connection string work with the path you've given, it should look somewhat like this:
Visual Studio 2012 (SQL Server 2012):
<connectionStrings>
<add name="myFirstConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;Integrated Security=True;AttachDBFilename="C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf";Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Visual Studio 2010 (SQL Server 2010):
<connectionStrings>
<add name="myFirstConnectionString"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename="C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf";User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
But you should consider moving the database file to the App_Data folder in your project, and then use AttachDBFilename=|DataDirectory|MyFirstTask.mdf instead.
You should place you .mdf in App_Data folder, then you can use this
<connectionStrings>
<add name="myFirstConnectionString"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|MyFirstTask.mdf;
User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
With C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf, if you move your application to another machine, that path might not exist
|DataDirectory| maps to your application App_Data folder

The default connection string for Membership framework in ASP.NET

What is the default connection string for ASP.NET applications?
I have written a simple ASP.NET application which uses Membership framework, but I haven't specified "connectionString" in my web.config. Nevertheless, the application is able to connect to a database. What database it connects to? What's the connection string for it and where it is located in my filesystem?
Thanks.
The default generated connection-string for a ASP.NET MVC3 application is
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
The file is located in the App_Data folder in the websites root

EF Code First with SQL Server Express 2012 ConnectionString

Everything works just fine with the following connection string.
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
I recently installed SQL Server 2012 Express on my local machine to test with, but I cannot make the connection. Here is my connection string using Windows Authentication.
<add name="ApplicationServices" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
I'm a total noob who tried his best to search the forums, but am unable to defer my solution from the 'Questions with similar titles' section. Any help is greatly appreciated.
EntityFramework code first uses a defaultConnectionFactory in the app.config or the web.config file which will automatically connect to .\SQLEXPRESS. This configuration looks like this:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
</entityFramework>
If you're using EF Code First, you probably have a class derived from DbContext to use as context. By design, EntityFramework will look for a connection string having the same name as your context class and use that one instead of the defaultConnectionFactory. This is how I'm using it:
<connectionStrings>
<add name="ObjectContext"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=My.Db.Name; Integrated Security=True; MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
What I'm suggesting is to check that EF doesn't use it's defaultConnectionFactory and even force overriding that by adding the connection string named after your context.
You should also check this blog article which gives great details about the EF configuration file.
Are you sure this part of the connection is right?
"Data Source=.\SQLEXPRESS [Name];
I've not used SQL Server 2012, but try to remove the [Name] text.
This worked for me
add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS;
Initial Catalog=Movies;
Integrated Security="True" providerName="System.Data.SqlClient"
I was working through this tutorial and had to work it out. The MovieDBContext is created in code in the model of an mvc application
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}
This automates the IDE creating the controller class but it wouldn't work till I got the connection string right in the web.config file.

web.configuration file in visual studio 2010

Hello i want to transfer my web application to the remote server, this is my local web.config file, can someone pls help me with this? I am using godaddy.I know i have to use the remove .. but i don't know how to do it using visual studio 2010. I am also confuse with the add name="applicationservices". in visual studio 2005 its <add name="LocalSqlServer"
Please i need help and clarification
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
1: You need to upload your database to your server.
2: Use godaddy's functionality to attach that database to their SqlServer.
3: Adjust your connectionstring to point to the DB on godaddy's server. You will have to ask them for the format.
4: Adjust your web.config.
Check if this helps:

Godaddy ASP.NET membership database woes

I purchased a Windows shared hosting account on godaddy that came with 2 MSSQL databases. I setup one to hold my site data and the other installed aspnet membership schema to store site members. The site works perfectly even displaying data from the 1st database. However when I try to login or register I get this nasty error
Exception Details:
System.Configuration.Provider.ProviderException:
The SSE Provider did not find the
database file specified in the
connection string. At the configured
trust level (below High trust level),
the SSE provider can not automatically
create the database file.
Ive gone through my web.config and there's nothing wrong with my 2 connection strings. It seems godaddy has a problem with using 2 mssql databases simultaneously when 1 is for membership.
Does anyone know a solution or a workaround?
I hope my experience benefits every one. Basically if you want to avoid aspnet membership problems on godaddy always use "LocalSqlServer" as the connectionstring. i.e
<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" connectionStringName="LocalSqlServer"
..other attributes here... />
</providers>
Then create the "LocalSqlServer" connectionString...remember to remove it first
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data Source=xxxx; Initial Catalog=xxx; User ID=xxx; Password=xxx;"
providerName="System.Data.SqlClient" />
</connectionStrings>
I ran into same problem and am using MVC3. Above solution works but with some other changes in MVC3. It took me long time to figure it out so if anybody has similar issue in MVC3 it might help them:
Search for "connectionStringName" in web.config and replace the name with connectionStringName="LocalSqlServer"
Also under connectionstrings make sure
-To add (As this is important for all who are using shared hosting it will replace machine.config LocalSqlServer connectionstring with yours.)
-Keep your current connectionstring (In my case it is FilmiDb, this is required for you to connect to the database in EF model. Without this you will get errors.)
<connectionStrings>
<remove name ="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Initial Catalog=SofilmiDb;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="FilmiDb" connectionString="Data Source=.\SQLExpress;Initial Catalog=FilmiDb;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>

Resources