Create a jTDS connection string

As detailed in the jTDS Frequenlty Asked Questions, the URL format for jTDS is: jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;…]] So, to connect to a database called “Blog” hosted by a MS SQL Server running on MYPC, you may end up with something like this: jdbc:jtds:sqlserver://MYPC:1433/Blog;instance=SQLEXPRESS;user=sa;password=s3cr3t Or, if you prefer to use getConnection(url, “sa”, “s3cr3t”): jdbc:jtds:sqlserver://MYPC:1433/Blog;instance=SQLEXPRESS EDIT: Regarding your Connection … Read more

SQL Server Connection Strings – dot(“.”) or “(local)” or “(localdb)”

. and (local) and YourMachineName are all equivalent, referring to your own machine. (LocalDB)\instance is SQL Server 2012 Express only. The other parts are depending on how you install – if you install with an instance name – then you need to spell that instance name out (SQL Server Express by default uses the SQLEXPRESS … Read more

What is the connection string for localdb for version 11

Requires .NET framework 4 updated to at least 4.0.2. If you have 4.0.2, then you should have HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v4.0.30319\SKUs.NETFramework,Version=v4.0.2 If you have installed latest VS 2012 chances are that you already have 4.0.2. Just verify first. Next you need to have an instance of LocalDb. By default you have an instance whose name is a single … Read more

How to read connection string in .NET Core?

The posted answer is fine but didn’t directly answer the same question I had about reading in a connection string. Through much searching I found a slightly simpler way of doing this. In Startup.cs public void ConfigureServices(IServiceCollection services) { … // Add the whole configuration object here. services.AddSingleton<IConfiguration>(Configuration); } In your controller add a field … Read more

EntityFramework code-first custom connection string and migrations

If your migration does not work correctly try to set Database.Initialize(true) in DbContext ctor. public CustomContext(DbConnection connection) : base(connection, true) { Database.Initialize(true); } I have similar problem with migrations. And in my solution I have to always set database initializer in ctor, like below public CustomContext(DbConnection connection) : base(connection, true) { Database.SetInitializer(new CustomInitializer()); Database.Initialize(true); } … Read more

How do I set a connection string config programmatically in .net?

I’ve written about this in a post on my blog. The trick is to use reflection to poke values in as a way to get access to the non-public fields (and methods). eg. var settings = ConfigurationManager.ConnectionStrings[ 0 ]; var fi = typeof( ConfigurationElement ).GetField( “_bReadOnly”, BindingFlags.Instance | BindingFlags.NonPublic ); fi.SetValue(settings, false); settings.ConnectionString = “Data … Read more