I try to connect to my database(which is recently moved to another server) with EF.
Server name is :SERVER-PC
Version of MSSQL : Microsoft SQL Server 2014 - 12.0.2000.8
The instance name when I get it using xp_regread sp: MSSQL12.MSSQLSERVER
I want to ad both instance name , and server name in connection string.
this is my connectionstring which I got help from this link
<add name="DefaultConnection" connectionString="data source= SERVER-PC\MSSQL12.MSSQLSERVER; Initial Catalog=FoodDB;Integrated Security=True" providerName="System.Data.SqlClient" />
but when I run the project , this error happens:
error : {"The provider did not return a ProviderManifestToken
string."}
An error occurred while getting provider information from the
database. This can be caused by Entity Framework using an incorrect
connection string. Check the inner exceptions for details and ensure
that the connection string is correct.
Could anyone please give me a help?
Note: I want to use both server name and Instance name (intentionally) in connection string. (assume the instance is not default)
The EF unable to determine the SQL Server store version:
-- Get Server name
SELECT ##servername
-- Get service name
SELECT ##servicename
MSSQL12.MSSQLSERVER = instance Id and not name!
<add name="DefaultConnection" connectionString="data source= .\; Initial Catalog=FoodDB;Integrated Security=True" providerName="System.Data.SqlClient" />
or
<add name="DefaultConnection" connectionString="data source= SERVER-PC\; Initial Catalog=FoodDB;Integrated Security=True" providerName="System.Data.SqlClient" />
Note: To connect to the default instance you don't specify the instance name, only the server name.
MSSQLSERVER = default name
Related
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.
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
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
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
I am able to auto-generate a SQL Server CE 4.0 *.sdf file using code-first generation as explained by Scott Guthrie here. The connection string for the same is as follows:
<add name="NerdDinners" providerName="System.Data.SqlServerCe.4.0"
connectionString="data source=|DataDirectory|NerdDinner.sdf"/>
However if I try to generate an mdf instead using the following connection string, it fails to do so with the following error - "The provider did not return a ProviderManifestToken string.".
<add name="NerdDinners" providerName="System.Data.SqlClient" connectionString="data
source=|DataDirectory|NerdDinner.mdf"/>
Even directly hooking into a SQLEXPRESS instance using the following connection string fails
<add name="NerdDinners" providerName="System.Data.SqlClient" connectionString="Data
Source=.\SQLEXPRESS;Initial Catalog=NerdDinner;Integrated Security=True"/>
Does EF 4 only support SQL CE 4.0 for database creation from a model for now or am I doing something wrong here?
I was able to get this connection string to work with SQL Express on the same tutorial.
<add name="NerdDinners" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=NerdDinners; AttachDbFilename=|DataDirectory|NerdDinners.mdf; Integrated Security=True; User Instance=True" providerName="System.Data.SqlClient" />
Hope this helps someone in the future.
As a side note. If you're struggling to get the database to auto-create, it could well be because the database user you are using hasn't been given sufficient permissions. I was able to simply go the Security of the SQL Instance (not the database) and amend the Securables of the specific login so that it had the permission to Create Any Database (I didn't Grant any additional rights) and it allows EF4 to do its thing.