Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 4.0 C# initialization string does not conform Login error

I have been writing a small web application in C# .NET4.0 to try and learn about it and get used to writing applications with it.

My application is very simple; it has a home page, a login button which takes you to the login form, and when you login you can go to an admin page.

The entire login process is done through the .NET login controls, and my database was created using the Aspnet_regsql.exe command through the visual studio command prompt (2010).

I had only been building and testing on my local machine up until now, and now want to try and test on a server with IIS7.

I have setup the site correctly in IIS7, and I can build and upload the site without any problems - that is - until I try to login. The version of SQL I was using on my local machine is 2008 R2, whereas the version of SQL on the server is plain 2008. Because of this, I couldn't just backup my local database and restore it to SQL on the server, so I generated scripts instead and used those scripts to create the database on the server.

Now, when I try to login to the site which is on the server, I get the following error:

Format of the initialization string does not conform to specification starting at index 0.

After trying to look around the internet for a solution I found that it could have just been a problem with my connection strings, so I tried changing them to all sorts of different things with no success.

My application in visual studio is a solution with 3 projects; a DAL, BLL and the Application itself.

I looked for all of the connection strings I could find in the whole solution, and these are the strings I have right now:

DAL (app.config) (This has changed now - please see 'EDIT 2' at the bottom of the question)

<add name="DAL.Properties.Settings.APPNAMEConnectionString"
   connectionString="Data Source=localhost;Initial Catalog=(DATABASE NAME);uid=(USER ID);pwd=(PASSWORD)"
   providerName="System.Data.SqlClient" />

Application (web.config) (This has changed now - please see 'EDIT 2' at the bottom of the question)

<add name="LocalSqlServer" connectionString="server=localhost;database=(DATABASE NAME);uid=(USER ID);pwd=(PASSWORD)"/>

This is the first time I have ever tried to put a C# .NET 4.0 application onto a server, so I really have no idea what I am doing wrong.

Any help would be greatly appreciated!

EDIT 1:

At the request of Dan F here is the membership code I could find in my web.config file:

    <membership>
        <providers>
            <clear/>
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            connectionStringName="LocalSqlServer"
            applicationName="/APPNAME"
            enablePasswordRetrieval="false"
            enablePasswordReset="true"
            requiresQuestionAndAnswer="false"
            requiresUniqueEmail="true"
            passwordFormat="Hashed"
            maxInvalidPasswordAttempts="5"
            minRequiredPasswordLength="5"
            minRequiredNonalphanumericCharacters="0"
            passwordAttemptWindow="10"
            passwordStrengthRegularExpression=""/>
        </providers>
    </membership>
    <profile>
        <providers>
            <clear/>
            <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/APPNAME" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </providers>
    </profile>
    <roleManager enabled="true">
        <providers>
            <clear/>
            <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/APPNAME" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <add name="AspNetWindowsTokenRoleProvider" applicationName="/APPNAME" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </providers>
    </roleManager>

EDIT 2: I just tested using the DAL to get out a list of users from the membership table that aspnet_regsql.exe generates and it worked fine. So I copied over the connection string from the DAL app.config to the application web.config so that they are exactly the same, but I still get errors when trying to login.

I also decided to try and use the Membership.GetUser() function in the code behind just to see if it would work, and it comes up with the same initialization string error for that too.

Just for reference my connection string in both the app.config and web.config is now:

Data Source=.;Initial Catalog=(DATABASE);User Id=(USERID);Password=(PASSWORD);
like image 456
Lucas Avatar asked Jul 16 '11 10:07

Lucas


1 Answers

Well, I finally found my problem. In order to save time trying to sort out the cs files from the aspx files and all of the other files which you don't actually need to upload for a .NET application, I have been using the 'Build Deployment Package' button which you can see when you right click on your project in the Solution explorer.

Being new to .NET and Visual Studio I didn't realise that this was actually changing my web.config file.

I thought everything was fine because the web.config file that I was editing (the one which wasn't generated in the deployment package) had the correct connection string of:

Data Source=.;Initial Catalog=(DATABASE);User Id=(USERID);Password=(PASSWORD);

But the connection string in the web.config which I was uploading (the one in the deployment package) had been changed to:

$(ReplacableToken_test-Web.config Connection String_0)

I changed this to the correct connection string and now it is working as expected.

like image 139
Lucas Avatar answered Sep 28 '22 04:09

Lucas