9

Is there an easy way to get the connection string of a database listed in the connection window of LINQPad (other than using the object explorer of Visual Studio)?

tuncalik
  • 1,124
  • 1
  • 14
  • 20
  • It would help if you say what you've already tried. But most likely you simply need to specify the server as `\` without an instance name as mentioned here: http://stackoverflow.com/questions/7010735/connect-linqpad-to-remote-sql-sever – Frank van Puffelen Aug 18 '14 at 12:54
  • 6
    Is the connection working? If so then try `this.Connection.ConnectionString.Dump();` – sgmoore Aug 19 '14 at 08:10
  • Thanks, this.Connection.ConnectionString works. – tuncalik Aug 19 '14 at 14:29

3 Answers3

16

Making sgmoore's comment into an answer:

try this.Connection.ConnectionString.Dump();

Community
  • 1
  • 1
Jay Walker
  • 4,654
  • 5
  • 47
  • 53
  • 1
    I might be doing something wrong, but I have tried this against an OData connection in LinqPad and only get an error : CS1061 'UserQuery' does not contain a definition for 'Connection' and no extension method 'Connection' accepting a first argument of type 'UserQuery' could be found (press F4 to add a using directive or assembly reference). I have tried all available languages - anyone any ideas? – leinad13 Jan 27 '17 at 11:41
  • 1
    this.Connection only exists if you've selected a connection in the Connection dropdown at the top of Linqpad's editor window. – Joel Malone Aug 31 '17 at 02:58
  • 1
    It is `this.Database.Connection.ConnectionString` at least in version 5.36 – ZorgoZ Feb 20 '19 at 12:09
4

In LinqPad 5 if your Language dropdown is set to C# Program and you have a database selected in the Connection dropdown, then you can get your string using

string c = LINQPad.Util.CurrentDataContext.Connection.ConnectionString;
Mike Brady
  • 313
  • 2
  • 7
0

In LinqPad7 you do:

this.Database.GetDbConnection().ConnectionString

This will show you the connection string.

John S
  • 7,909
  • 21
  • 77
  • 145
  • I have to use this `this.Database.GetConnectionString()`. I'm using EF Core 6 provider. – Will Huang Jan 07 '23 at 19:39
  • I use LinqPad7, but i can't find this.Database !! when i use sql server it marked red. Do you know why? – s.c Jan 16 '23 at 02:38