I'm using EF code-first and I want it to create the new database in SQL Server Management Studio instance instead of using the integrated SQL Server in Visual Studio.
I added this to my web.config:
<connectionStrings>
<add name="BillFo"
connectionString="Data Source=SELANL293;Initial Catalog=Billfo;Integrated Security=True"/>
</connectionStrings>
But it doesn't help. No nothing happens, nothing in the integrated SQL Server and nothing in my SQL Server Management Studio. How do I make it create my database in Management Studio rather then the SQL Server in Visual Studio?
try add this section
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="connection string......"/>
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="..." providerName="System.Data.SqlClient" connectionString="......" />
</connectionStrings>
you do not have to use <parameters> property , you can use your currently connection string configuration
Try
<connectionStrings>
<clear />
<add name="YourEFContextName" connectionString="Data Source=localhost\SqlServerInstanceName; Initial Catalog=DataBaseName; User ID=UserName; password=YourPassword; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
The section entityFramework should be created automatically.
Related
I've been using membership in vs2010 and never had a problem using it. Now i'm using VS2012 and am currently having trouble. In my Web Site Administration Tool, i get the error message "Unable to connect to SQL Server database." I have run the regsql file. I'm using mssql 2012 not the express version and working on a local project
<add name="XXXDbConnectionString" connectionString="Data Source=Local-PC;Initial Catalog=XXXDb;Integrated Security=True" providerName="System.Data.SqlClient"/>
<roleManager enabled="true" defaultProvider="SqlRoleManager">
<providers>
<add name="SqlRoleManager"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="MyConnectionString"
applicationName="MyApplication" />
</providers>
</roleManager>
Just had to insert to rolemanager
I have setup a local installation of DNN7 using a database residing in another machine (sqlserver 2008).
I've tried to copy all the filesystem to a production server but keep the connection string the same, so use the exact same database.
I get the message
"The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty."
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
The application pool and IIS settings are the same in both machines. Any ideas of what am I missing?
You are missing following section in web.config
<connectionStrings>
<!-- Connection String for SQL Server 2005/2008 Express -->
<!-- Connection String for SQL Server 2005/2008
<add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke;uid=;pwd=;" providerName="System.Data.SqlClient" />
-->
</connectionStrings>
The problem had to do with the role membership provider.
For some reason the AspNetSqlMembershipProvider provider falls back at the default one which is in the machine.config (insided the .NET folder).
In dev environments with an SQLEXpress instance running, the machine.config has a connection string named 'LocalSqlServer' which points to the SQLExpress. That's why it worked in my dev environment.
The server on the other hand, doesn't have SQLExpress, so no LocalSqlServer connectionstring exists in the machine.config and therefore the error pops up.
The workaround I found in DNN forums is to add these lines inside the section of the web.config
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=dbserver;Integrated Security=false;Initial Catalog=dbName;User ID=dbUser;Password=dbPass" providerName="System.Data.SqlClient" />
I'm creating a simple ASP.NET MVC 4 application using Entity Framework and code-first. With SQL Server Express 2012, everything works fine when using Windows Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
However, when using the following for SQL Server Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=False; User Id=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
I receive an error:
"Login failed for user 'mysa'" ProviderIncompatibleException.
Am I missing something?
Is it possible that your *.mdf file is not attached to sql server instance?
Try attaching the myDb.mdf file to your database with SQL Management Studio and the change the connection string to
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; Category=myDb;Integrated Security=False; User=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
and don't forget to give the appropriate rights to your user
Before I begin I would like to say I have already checked thoroughly at www.connectionstrings.com and looked at all possible threads at this forum for an answer.
Right now my connection string is like this:
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
Its working, but I can only access it in my App_Data folder
I want to access this database from the SQL SSMS, therefore I have tried changing it like this:
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
Database=AspNetDb;InitialCatalog=ASPNETDB; User Id=kaneXtreme;Password=password123!;User Instance=true" providerName="System.Data.SqlClient"/>
I have also tried this
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Database=AspNetDb;
Initial Catalog=ASPNETDB; User Id=kaneXtreme;Password=password123!" providerName="System.Data.SqlClient" />
Both of which I have tried changing is resulting in this Configuration error when I open up localhost:
The entry LocalSqlServer has already been added.
Advice please.
You could try to clear your connection strings before adding the first one.
By default, there is a "hidden" LocalSqlServer connection string in your machine.config
<connectionStrings>
<clear/>
<add name="LocalSqlServer" and-so-on-and-so-forth ...
If your using a username and password I think you need to change Integrated Security=SSPI to Integrated Security=True
eg.
<add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASPNETDB;User id=kaneXtreme password=password123!;Integrated Security=True;" providerName="System.Data.SqlClient" />
I am trying to have access to my project from the browser, I have put it on my server .
My database is on SQL Server 2008 R2 .
When I try to login I have always this exception :
Invalid value for key 'attachdbfilename'
I think the problem is from my connection string but I can't fix it . I tried in many ways .
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Initial Catalog=DataUi;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|DataUi.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Can someone help me ?
Thank you very much .
The AttachDbFileName= feature is available ONLY in the SQL Server EXPRESS edition. It is NOT compatible and supported on a "full" SQL Server installation.
If you have a full SQL Server, you have to attach your database to the SQL Server instance, and then reference it by its (logical) database name - not the physical file name:
<connectionStrings>
<add name="LocalSqlServer"
connectionString="server=.;database=DataUi;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
You should "Database" rather than "AttachDbFileName" as it is not recommended for production servers.
Hence your connection string should be:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Initial
Catalog=DataUi;Integrated Security=SSPI;Database=DataUi.mdf;User
Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
I think there's a missing \\ in your AttachDBFilename right after |DataDirectory|:
AttachDBFilename=|DataDirectory|\\DataUi.mdf