Changing Connection String to SQL Server Express has no effect - sql-server

Initially, my project (running on localhost with SQL Server Express) had a connection string to the database Test1:
<connectionStrings>
<add name="TestContext"
connectionString="data source=.\SQLEXPRESS; Integrated Security=SSPI; Initial Catalog=Test1; User Instance=true"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
Now, I want the same project uses a different database: Test2.
So I've changed the "Initial Catalog" in the connection string to Test2.
But, to my surprise, when I execute the application, the Test1 database is still the one to be used.
What am I doing wrong?
I've already try to stop/start the IIS and delete the "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" folder with no success.

Related

MVC4 Is my Connection String to SQL Server 2014 correct

I'm using Visual Studio 2012 for Web and I'm coding a MVC application. By default it uses a localDB but I want it on a SQL Server. I've installed SQL Server 2014 and my servername is C0208\SQLEXPRESS.
C0208 is my computer name
Named Instance: SQLEXPRESS
InstanceID: SQLEXPRESS
This is my connectionstring to the localdb
<add name="IssueContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=RecreationalServicesTicketingSystem;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\RecreationalServicesTicketingSystem.mdf" providerName="System.Data.SqlClient" />
I tried using this connection string and I don't know if it's correct or not
<add name="IssueContext" providerName="System.Data.SqlClient" connectionString="Data Source=C0208\SQLEXPRESS;User Id=C0208;Initial Catalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True" />
This looks more of an Entity Framework issue rather than the SQL connection string. Just check if you have updated the connection string everywhere. (app.config).
To Enable data migration you will have to run the following command in the Package Manager Console.
enable-migrations
if it gives an error than try the following command first
add-migration projectName
For more details check this link

DNN5 Shows Under Construction

I recently upgraded my PC from Windows 7 to Windows 8.1 and am now having problems resetting up my local DNN5 environment.
I pulled my DNN5 instance down from a remote git repo, and just finished importing all of the tables/data/stored procedures from the production DB to a local instance.
I have updated the connection strings in the web.config to reflect my new database, but still, no matter what I do, I am getting redirected to http://localhost/DNN5/Install/UnderConstruction.htm.
What am I missing?
for completeness, here are my connection strings and a screencap of my db:
<connectionStrings>
<add name="SiteSqlServer" connectionString="Data Source=KMCNUTT-7\DWYATTMSSQL;Initial Catalog=DNN5;User ID=sa;Password=******"
providerName="System.Data.SqlClient" />
<add name="DNN5ConnectionString" connectionString="Data Source=KMCNUTT-7\DWYATTMSSQL;Initial Catalog=DNN5;User ID=sa;Password=******"
providerName="System.Data.SqlClient" />
</connectionStrings>
This almost always happens when you are unable to connect to the database from DNN.
Navigate to
http://localhost/DNN5/Install/install.aspx
and see if it throws a connection error just to be sure.
Is this a local database? If so try using (local)\InstanceName (I assume your instance name is DWYATTMSSQL) so (local)\DWYATTMSSQL
Also make sure that you have SQL authentication enabled in SQL server, instead of Windows Authentication only, which is the default for SQL installations.

connection string is not working with my database on Microsoft SQL Server in ASP.NET MVC 4

I have this on my web.config file
<add name="EFDBContext"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=StadinPeli;
Integrated Security=True"
providerName="System.Data.SqlClient"/>
And yes in Server Explorer in visual studio 2012 professional edition, it works with
EFDBContext (WebUI).
But its the wrong database. Somehow this EFDBContext database copy its definitions from the database where I want it to connect all the time,
which is jon-pc\localdb#13158683.StadinPeli.dbo.
I checked properties from jon-pc\localdb#13158683.StadinPeli.dbo for its connection string
but it still connects to EFDBContext (WebUI).
Where is the problem, I have tried to correct this for 3 hours already.
(Localdb) as data source is probably wrong. Try updating it to (local) so your connection string looks like this
<add name="EFDBContext"
connectionString="Data Source=(local)\v11.0;Initial Catalog=StadinPeli;
Integrated Security=True"
providerName="System.Data.SqlClient"/>

how to setup MVC application to use sql server 2008 r2 express

I am trying to follow the tutorial on the building my first MVC application for here
all was good until I needed to run the application an entity framework should have done it's thing and create the data base for me, but for some reason I always get the same error :
The provider did not return a ProviderManifestToken string.
my question:
what are the necessary adjustments i need to do in order for the application to work?
here is my web.config file connection string section
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=Moran-Laptop;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
I think your data source is not correct. Does it work with:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
If you inspect the exception you will find out that there is InnerException as well which most probably points to SqlException and its inability to find the database or server. Your ConnectionString expects that you have Sql Server CE database available in your App_Data folder. The tutorial that you are looking does not yet tell you that you have to add a new SQL Server CE database to your App_Data folder. Check part 5 of the tutorial http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part5-cs
First off you need to change your connection strings to point to the servers instance of sql server rather than to your laptop
in your connection strings replace Moran-laptop with "server-name\db name" i.e. r2008sqlserver\movies

MVC3 changing default connection string error

I created an MVC3 Internet application and changed the default connection string to work with
.\SQLSERVER instead of the default .\SQLEXPRESS and get following error :
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server)
I tried creating an empty MVC3 application as well, which has no connection string by default and added mine with the same result.
The SQLSERVER instance is running and I can connect to it from management studio using windows authentication. Any connection string that I use gives same error, I cannot figure it out:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="data source=.\SQLSERVER;" providerName="System.Data.SqlClient" />
</connectionStrings>
To connect to your local default instance (i.e. SQLSERVER service name), for Data Source=..., use one of the following:
127.0.0.1
localhost
(local)
.
EDIT
Your connection string should resemble this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Checkout the different connection strings you can use with SQL Server. For example if you have a SQL Server installed on your local machine you could use the following connection string:
Data Source=127.0.0.1;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Obviously you will need to adjust the name of the database, the username and password to connect to.
If you want to use Windows Authentication to connect to the server:
Data Source=127.0.0.1;Initial Catalog=myDataBase;Integrated Security=SSPI;
Your connection string needs to look something like this:
<add name="NameOfConnection" connectionString="Data Source=localhost;Initial Catalog=OMSCING;Trusted_Connection=Yes" providerName="System.Data.SqlClient" />
Where you can replace localhost with a hostname or leave it like that if the server's local.
Perhaps I had to mention that I was using EF with code first approach, but the problems was due to the name of the connection string which should be the same name as your Context which you derive from DbContext, e.g.:
<connectionStrings>
<remove name="ApplicationServices"/>
<add name="MyContext"
connectionString="data source=localhost; Initial Catalog=CoolCars;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
as well make sure you remove the default machine.config connection string which is for .\SQLEXPRESS

Resources