lechj
lechj

Reputation: 1

Changing user in Connection String of web.config

Simple webpage backed by C# where the web.config has a connection string to sql server. We're trying to migrate that server, and this page to look to the new one. Whenever I modify the web.config, it produces a Server Error on the page. First I tried changing the Data Source Name to look at the new server. Then I just tried changing the User ID/password to our SA account. Both resulted in server error.

<add name="Directory" connectionString="Data Source=SERVERA; Database=Directory; User ID=phone_user; Password=XXXXX"/>

Stack Trace fails at SubSonic.SqlQuery.ExecuteReader()

Sql Query Exception: Format of the initialization string does not conform to specification starting at index 0.

Is there any additional information I need to provide?

Upvotes: 0

Views: 197

Answers (1)

Belogix
Belogix

Reputation: 8147

Try changing your connection string to one of the following:

Server=SERVERB;Database=Directory;User Id=phone_user;Password=XXXXXX;

or

Data Source=SERVERB;Initial Catalog=Directory;User Id=phone_user;Password=XXXXXX;

I am not sure Data Source and Database combination is 100% valid whereas the above two examples should work.

A great source information about connection strings (MS SQL Server) here: http://www.connectionstrings.com/sql-server/ and it has many others!

EDIT

In addition check you are getting / using connection string correctly, a simple example:

string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Directory"].ConnectionString;
using (var con = new SqlConnection(connectionString))
{
    ....
}

Upvotes: 2

Related Questions