Setting up connection string in ASP.NET to SQL SERVER

You can also use this, it’s simpler. The only thing you need to set is “YourDataBaseName”. <connectionStrings> <add name=”ConnStringDb1″ connectionString=”Data Source=localhost;Initial Catalog=YourDataBaseName;Integrated Security=True;” providerName=”System.Data.SqlClient” /> </connectionStrings> Where to place the connection string <?xml version=’1.0′ encoding=’utf-8′?> <configuration> <connectionStrings> <clear /> <add name=”Name” providerName=”System.Data.ProviderName” connectionString=”Valid Connection String;” /> </connectionStrings> </configuration>

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 … }

Entity Framework Timeouts

There is a known bug with specifying default command timeout within the EF connection string. http://bugs.mysql.com/bug.php?id=56806 Remove the value from the connection string and set it on the data context object itself. This will work if you remove the conflicting value from the connection string. Entity Framework Core 1.0: this.context.Database.SetCommandTimeout(180); Entity Framework 6: this.context.Database.CommandTimeout = … Read more

How can I set an SQL Server connection string?

.NET DataProvider — Standard Connection with username and password using System.Data.SqlClient; SqlConnection conn = new SqlConnection(); conn.ConnectionString = “Data Source=ServerName;” + “Initial Catalog=DataBaseName;” + “User id=UserName;” + “Password=Secret;”; conn.Open(); .NET DataProvider — Trusted Connection SqlConnection conn = new SqlConnection(); conn.ConnectionString = “Data Source=ServerName;” + “Initial Catalog=DataBaseName;” + “Integrated Security=SSPI;”; conn.Open(); Refer to the documentation.

Writing a connection string when password contains special characters

Backslashes aren’t valid escape characters for URL component strings. You need to URL-encode the password portion of the connect string: from urllib import quote_plus as urlquote from sqlalchemy.engine import create_engine engine = create_engine(‘postgres://user:%s@host/database’ % urlquote(‘badpass’)) If you look at the implementation of the class used in SQLAlchemy to represent database connection URLs (in sqlalchemy/engine/url.py), you … Read more

How to connect to Oracle using Service Name instead of SID

http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/urls.htm#BEIDHCBA Thin-style Service Name Syntax Thin-style service names are supported only by the JDBC Thin driver. The syntax is: @//host_name:port_number/service_name For example: jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename So I would try: jdbc:oracle:thin:@//oracle.hostserver2.mydomain.ca:1522/ABCD Also, per Robert Greathouse’s answer, you can also specify the TNS name in the JDBC URL as below: jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=blah.example.com)(PORT=1521)))(CONNECT_DATA=(SID=BLAHSID)(GLOBAL_NAME=BLAHSID.WORLD)(SERVER=DEDICATED)))