Skip to content

Can I specify a different connection string to use with my complied entities than the one in the dll? #2

@ChrisMagnuson

Description

@ChrisMagnuson

I have a dll from an existing application and have found the class that implements the entity framework DB Context.

If I run:

Add-Type -AssemblyName System.Configuration
[appdomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "C:\Image\ImageService.exe.config")

[Reflection.Assembly]::LoadFrom("C:\Image\ImageService.Data.dll")
$ctx = New-Object ImageService.Data.TCDataContext
$ctx

$ctx.Database.Connection.ConnectionString

I can see that the default connection string is pointing to a local sqlexpress instance that must have been used on the developers system.

If I run:

$ctx.Database.Connection.ConnectionString = "data source=sql.epsilon.domain.prv;initial catalog=ImageServiceDatabase;integrated security=True"

I can change this connection string and am able to confirm via wireshark that while before I was not making any tcp connections to desired SQL server, after this if I look at the properties of the $ctx object it results in a persistent tcp connection being established to the SQL server.

I think accessing entity framework through this context object is ultimately a dead end (or so difficult I should be writing c# instead) and what I want to do instead is leverage EntityShell but when I load the assembly in EntityShell it creates the PS drive but nothing is there:

PS C:\Users\cmagnuson\Downloads\EntityShell-master\EntityShell> import-module entityshell
PS C:\Users\cmagnuson\Downloads\EntityShell-master\EntityShell> get-item "C:\Image\ImageService.Data.dll" | import-module
PS C:\Users\cmagnuson\Downloads\EntityShell-master\EntityShell> new-psdrive -name Imageservice -root '' -psp entityprovide
r -context [ImageService.Data.TCDataContext]

Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
----           ---------     --------- --------      ----                                               ---------------
Imageservice                             EntityProv...


PS C:\Users\cmagnuson\Downloads\EntityShell-master\EntityShell> cd Imageservice:
PS Imageservice:\> ls
ls : Object reference not set to an instance of an object.
At line:1 char:1
+ ls
+ ~~
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetChildItemCommand

PS Imageservice:\>

I assume this is because the connection string is wrong.

How can I change the connection string used by entity framework under the hood of the EntityShell psprovider?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions