0

I am having the following error

 public int  GetRegisteredUsersCount()
    {

        string myScalarQuery = "select count(*) from aspnet_Users where isActivated = 0";
        string cs = ConfigurationManager.ConnectionStrings["uniteCms"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(cs.ToString());

        SqlCommand myCommand = new SqlCommand(myScalarQuery, myConnection);
        myCommand.Connection.Open();
        int count = (int) myCommand.ExecuteScalar();
        myConnection.Close();

        return count;
    }

but yet i have the connection string in my webconfig connections string section

 <add
name="uniteCms"
connectionString="Data Source=myserver;Initial 
Catalog=DB_9DF962_davidbuckleyni37;User ID=DB_9DF962_davidbuckleyni37_admin;Password="
providerName="System.Data.SqlClient"
/>

enter image description here

3
  • change initial catalog to database Commented Nov 8, 2015 at 16:33
  • connectionstrings.com will help you. Commented Nov 8, 2015 at 16:35
  • @KenTucker please provide and answer ill mark u up Girggi its its stackoverflows policy not to provide links outside of asp.net documentation Commented Nov 8, 2015 at 16:44

2 Answers 2

1

What data source instance are you using? If you are using sqlexpress then you should put Data source=myserver\sqlexpress. For any instance it should be like Data Source=ServerName\InstanceName

Sign up to request clarification or add additional context in comments.

Comments

1

You seem to have line breaks in your connection string which also is what the error implies (ie Initial\r\nCatalog).

Make sure to not put any line breaks within the attribute values.

<add
  name="uniteCms"
  connectionString="Data Source=myserver;Initial Catalog=DB_9DF962_davidbuckleyni37;User ID=DB_9DF962_davidbuckleyni37_admin;Password="
  providerName="System.Data.SqlClient" />

If you really want to break it down you can try adding it after the delimiters in the connection string but I'm not sure it will be allowed there either.

This might work, might fail with a crash or might fail without saying anything and giving you an exception later about being unauthorized (because only the first line was used).

<add
  name="uniteCms"
  connectionString="Data Source=myserver;
                    Initial Catalog=DB_9DF962_davidbuckleyni37;
                    User ID=DB_9DF962_davidbuckleyni37_admin;
                    Password="
  providerName="System.Data.SqlClient" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.