I tried quite many various of the connection strings to get it working as follows:
<connectionStrings>
<add
name="CodeFirstTest"
providerName="System.Data.SqlClient"
connectionString="Server=ma\SQLEXPRESS;Initial Catalog=test;Integrated Security=true;Truested_Connection=true;"/>
</connectionStrings>
Exception message:
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
I'm not sure the exact SQL Server I installed. But by SQL Server Management Studio I can see as properties :-
MA is the name of he pc windows 8.1 installed. Also I tried Server=.\SQLEXPRESS. I get same exception.
Then tried the following:
<connectionStrings>
<add name="Default"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=MA\LOCALDB#57E60DE5;Database=test;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient"/>
</connectionStrings>
I get exception:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified).
Then modified data source=ma\SQLEXPRESS. Still get same error. How do I connect local db in .net / C#?
Change your connection string to be like below (notice the part Server=ma\\SQLEXPRESS;)
connectionString="Server=ma\\SQLEXPRESS;Initial Catalog=test;Integrated Security=true;Truested_Connection=true;"/>
Also notice the part in your connection string Truested_Connection=true;; it should be Trusted_Connection=True;. There is a spelling mistake.
Those keywords much match exactly else an exception would be thrown saying unknown keywords
Related
This is my connection string:
<add name="EntityContext"
connectionString="data source=.\SQLEXPRESS;
AttachDbFileName=|DataDirectory|\PasLockProduction.mdf;
Database=PasLockProduction;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
I get this 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Most likely your DataDirectory is not what you think it is. In the Interactive window or even in your code where you can set a breakpoint do this to see where that directory is:
var ddir = AppDomain.CurrentDomain.GetData("DataDirectory");
To set the directory to where your database file is :
AppDomain.CurrentDomain.SetData("DataDirectory", "<path to file...");
Try someting like this.
<connectionStrings>
<add name="EntityContext" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=c:\folder\PasLockProduction.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";/>
</connectionStrings>
Story :
I am trying to create an ASP.NET application hosted on Google Cloud.
This application needs database access to store some data and I am already using Entity Framework to access a local database.
So I am following this tutorial, hoping to find a way to host my database on Google Cloud :
https://cloud.google.com/dotnet/docs/getting-started/using-cloud-sql
But in the Configuring settings's part during the sixth step I get an error.
Configuration :
File : Web.config
<appSettings>
<add key="GoogleCloudSamples:ProjectId" value="area-185910" />
<add key="GoogleCloudSamples:BookStore" value="mysql" />
</appSettings>
<connectionStrings>
<add name="AreaDbEntities" connectionString="metadata=res://*/Models.AreaModel.csdl|res://*/Models.AreaModel.ssdl|res://*/Models.AreaModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\AreaDb.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="LocalMySqlServer" connectionString="Server=IP;Database=NAME;Uid=USERNAME;Pwd=USERPWD" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Error :
Visual studio Error
Website's page's error :
[SqlException (0x80131904): 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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
Question :
Is someone able to explain how to make a database migration from a local EF database (with Entity Framework) to Google Cloud ?
Or is someone able to solve the error ?
Thank you in advance !
I've implemented Identity & OWIN authentication to my existing asp.net web form application. I referred to the site:
https://learn.microsoft.com/en-us/aspnet/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project
I am having problem with connection string for entity framework code first approach. I referred to the site: http://odetocode.com/Blogs/scott/archive/2012/08/14/a-troubleshooting-guide-for-entity-framework-connections-amp-migrations.aspx for help. But none of them is working.
I use VS 2015, SQL Server 2014 & Windows 10 OS.
For SQL Server authentication (Windows authentication) my server name is : DESKTOP-07C2G55.
I changed my connection string as told in the sites but none of them worked. My first connection string is::
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=DESKTOP-07C2G55;Initial Catalog=WebFormsIdentity;AttachDbFilename=|DataDirectory|\WebFormsIdentity.mdf;Trusted_Connection=Yes;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
On using this connection string when I try to register any user I am getting error as:
Directory lookup for the file "c:\users\myPC\documents\visual studio 2015\Projects\RENTAL\RENTAL\App_Data\WebFormsIdentity.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Directory lookup for the file "c:\users\myPC\documents\visual studio 2015\Projects\RENTAL\RENTAL\App_Data\WebFormsIdentity.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Then I run the following commands in my VS console. I get:
PM> Get-Service | Where-Object {$_.Name -like '*SQL*'}
Status Name DisplayName
------ ---- -----------
Running MSSQLFDLauncher SQL Full-text Filter Daemon Launche...
Running MSSQLSERVER SQL Server (MSSQLSERVER)
Running MSSQLServerOLAP... SQL Server Analysis Services (MSSQL...
Stopped SQLBrowser SQL Server Browser
Stopped SQLSERVERAGENT SQL Server Agent (MSSQLSERVER)
Running SQLWriter SQL Server VSS Writer
PM> SqlLocalDb info
MSSQLLocalDB
Then I changed my connection string, chaned the datasource to Data Source=MSSQLLocalDB:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=MSSQLLocalDB;Initial Catalog=WebFormsIdentity;AttachDbFilename=|DataDirectory|\WebFormsIdentity.mdf;Trusted_Connection=Yes;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I get the error
Invalid value for key 'attachdbfilename'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Invalid value for key 'attachdbfilename'.
Again I changed my connection string to Data Source= .\SQLEXPRESS
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=WebFormsIdentity;AttachDbFilename=|DataDirectory|\WebFormsIdentity.mdf;Trusted_Connection=Yes;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I got the 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I can not figure out what is the problem whether the cause of the problem is connection string or any where else in the code. In other solutions, it is mentioned to edit DBContext Class, but in the tutorial there is no such class created. I am not using MVC, simple web form application trying to implement Identity and OWIN module. Please help me.
The output from your PowerShell script shows that you have a default instance (with the "instance" name of MSSQLSERVER) of SQL Server running:
Running MSSQLSERVER SQL Server (MSSQLSERVER)
This means, you can use Data Source=. (or Data Source=(local)) for your server name (you must not define an instance name to connect to the default instance), define the database name in Initial Catalog, and drop that AttachDbFileName crap once and for all (and let SQL Server handle all the file-related ins and outs - don't mess around with .mdf database files yourself!):
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=.;Initial Catalog=WebFormsIdentity;Trusted_Connection=Yes;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I'm using Visual Studio Express 2013 for web and I'm following this tutorial : http://www.codeproject.com/Articles/791740/Using-AngularJs-ASP-NET-MVC-Web-API-and-EntityFram which specifies this connection to connect ot the db:
<add name="MainDb" connectionString="Server=localhost; Database=SimpleTaskSystemDb; Trusted_Connection=True;" providerName="System.Data.SqlClient" />
but when I run Update-Database I get this 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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
I've also finished the Music Store app which is working fine and the connection there is different:
<add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MusicStore.sdf" providerName="System.Data.SqlServerCe.4.0"/>
I tried a similar connection string but that didn't work either.
No Entity Framework provider found for the ADO.NET provider with
invariant name 'System.Data.SqlServerCe.4.0'. Make sure the provider
is registered in the 'entityFramework' section of the application
config file.
However the Music Store app.config file does not reference System.Data.SqlServerCe.4.0 but I added it to this app anyway and then I get back to my original error.
Any help would be greatly appreciated.
Here are some of the sample connection strings I have described every connection string with full details
For Local Sql server (BuildIn Sql Server Express into Visual Studio).
For Sql Server instance which comes default with visual studio you can use following connection string
<connectionStrings>
<add name="ConnectionStringName" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=YourDatabaseName;Integrated Security=True"
providerName="System.Data.SqlClient" />
For Sql Server Which Has been installed seperately such as Evaluation Edition etc
<connectionStrings>
<add name="ConnectionStringName" connectionString="Data Source=YourPCName-PC\ServerInstanceName;Initial Catalog=YourDatabaseName;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
For CompactEdition of Sql server you can use provider name as
providerName="System.Data.SqlServerCe.4.0"
I am trying to use code-first approach of Entity Framework in my asp.net mvc application. Below is my connection string which was autogenerated...
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
Whenever I press F5, the following error occurs:
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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
What am I doing wrong??
I have SQL Server 2008 Enterprise edition installed. I am trying to connect to SQL Server using Windows authentication. I am also following a video tutorial so there may not be anything wrong with code
IF you have SQL Server Enterprise edition, you most likely won't have it installed as SQLEXPRESS instance (that's the default for the SQL Server Express installations that come with Visual Studio).
More likely than not, you have the unnamed default instance - so try to use this connection string:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.;Database=YourDatabaseName;Integrated Security=SSPI;
providerName="System.Data.SqlClient" />
</connectionStrings>
Not sure if your application really uses the ApplicationServices connection string - if not, adapt the one your app is using! Also, you'll need to replace the YourDatabaseName with the actual database name that you're using in your application.
If you are trying to connect to an instance of SQL server that's installed on your machine, you'll want to use a connectionString formatted to use that instead. Your current connectionString is trying to create a database file from which to work, rather than building a database in your SQL server instance.
Try something like this;
connectionString="data source=localhost;user id=<user with dbo access>;password=<user password" providerName="System.Data.SqlClient" />