c# - Entity Framework code first approach connection string configuration -


i've implemented identity & owin authentication existing asp.net web form application. referred site: https://docs.microsoft.com/en-us/aspnet/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project

i having problem connection string entity framework code first approach. referred site: http://odetocode.com/blogs/scott/archive/2012/08/14/a-troubleshooting-guide-for-entity-framework-connections-amp-migrations.aspx help. none of them working.

i use vs 2015, sql server 2014 & windows 10 os.

for sql server authentication (windows authentication) server name : desktop-07c2g55.

i changed connection string told in sites none of them worked. 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 connection string when try register user getting error as:

directory lookup file "c:\users\mypc\documents\visual studio 2015\projects\rental\rental\app_data\webformsidentity.mdf" failed operating system error 5(access denied.).

create database failed. file names listed not created. check related errors.

description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.data.sqlclient.sqlexception: directory lookup file "c:\users\mypc\documents\visual studio 2015\projects\rental\rental\app_data\webformsidentity.mdf" failed operating system error 5(access denied.).

create database failed. file names listed not created. check related errors.

then run following commands in vs console. 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 changed connection string, chaned datasource 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 error

invalid value key 'attachdbfilename'.

description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.argumentexception: invalid value key 'attachdbfilename'.

again changed connection string 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 error:

a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: sql network interfaces, error: 26 - error locating server/instance specified)

description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.data.sqlclient.sqlexception: network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: sql network interfaces, error: 26 - error locating server/instance specified)

i can not figure out problem whether cause of problem connection string or else in code. in other solutions, mentioned edit dbcontext class, in tutorial there no such class created. not using mvc, simple web form application trying implement identity , owin module. please me.

the output powershell script shows have default instance (with "instance" name of mssqlserver) of sql server running:

running  mssqlserver        sql server (mssqlserver)               

this means, can use data source=. (or data source=(local)) server name (you must not define instance name connect default instance), define database name in initial catalog, , drop attachdbfilename crap once , (and let sql server handle file-related ins , outs - don't mess around .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> 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -