How do I use Web.Config transform on my connection strings?

This works for me but I too have found it to be a bit flakey at times. You will need to create another file called Web.Config.Release and fill it with the following: <configuration xmlns:xdt=”http://schemas.microsoft.com/XML-Document-Transform”> <connectionStrings> <add name=”local” connectionString=”Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword” xdt:Transform=”SetAttributes” xdt:Locator=”Match(name)”/> </connectionStrings> <system.web> <compilation xdt:Transform=”RemoveAttributes(debug)” /> </system.web> <appSettings> <add key=”default_db_connection” value=”local” xdt:Transform=”SetAttributes” xdt:Locator=”Match(key)” … 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

Connect to SQL Server Database from PowerShell

Integrated Security and User ID \ Password authentication are mutually exclusive. To connect to SQL Server as the user running the code, remove User ID and Password from your connection string: $SqlConnection.ConnectionString = “Server = $SQLServer; Database = $SQLDBName; Integrated Security = True;” To connect with specific credentials, remove Integrated Security: $SqlConnection.ConnectionString = “Server = … Read more

System.Data.SqlClient.SqlException: Login failed for user

Just set Integrated Security=False and it will work ,according to a comment difference between True and False is: True ignores User ID and Password if provided and uses those of the running process, SSPI(Security Support Provider Interface ) it will use them if provided which is why MS prefers this. They are equivalent in that … Read more

SQL Express connection string: mdf file location relative to application location

Thanks everyone, I used a combination of your responses. In my app.config file my connection string is defined as follows <add name=”MyConnectionString” connectionString=”Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Database=MyDatabaseForTesting;Trusted_Connection=Yes;” /> In my unit test class I set the DataDirectory property using the following [TestInitialize] public void TestInitialize() { AppDomain.CurrentDomain.SetData(“DataDirectory”, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “Databases”)); // rest of initialize implementation … }

A network-related or instance-specific error occurred while establishing a connection to SQL Server [closed]

Sql Server fire this error when your application don’t have enough rights to access the database. there are several reason about this error . To fix this error you should follow the following instruction. Try to connect sql server from your server using management studio . if you use windows authentication to connect sql server … Read more

How to hide connection string, user name, pw when using source control?

What I find works is to check in a version of the file with blanked or dummy values and then to run: git update-index –assume-unchanged [fileName] Git will then stop monitoring changes to that file allowing you to put the real config info into it without fear of checking it in. If you later make … Read more