views:

758

answers:

3

I have a Web setup project. In the setup I have an input field where the user can insert a connectionstring. When I run the setup I get this error:

Error 1001. Unknown error (0x8000x5000)

To track where the error exists I create a file and in every method I write something to this file. Now I think the error is raised by this line:

string friendlySiteName = entry.Properties["ServerComment"].Value.ToString();

But I don't know how to correct this problem. I hope you can help me out!

Code:

    public override void Install(System.Collections.IDictionary stateSaver)
    {
        base.Install(stateSaver);

        // Retrieve configuration settings
        string targetSite = Context.Parameters["targetsite"];
        string targetVDir = Context.Parameters["targetvdir"];
        string targetDirectory = Context.Parameters["targetdir"];
        string targetConnectionString = Context.Parameters["targetconn"];

        FileStream f = new FileStream("c:\\myfile.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
        StreamWriter w = new StreamWriter(f);
        w.WriteLine("targetSite: " + targetSite);
        w.WriteLine("targetVDir: " + targetVDir);
        w.WriteLine("targetDirectory: " + targetDirectory);
        w.WriteLine("targetConnectionString: " + targetConnectionString);
        w.Close();
        w.Dispose();
        f.Close();
        f.Dispose();

        ConfigureWebConfig(targetSite, targetVDir, targetConnectionString);
    }

    void ConfigureWebConfig(string targetSite, string targetVDir, string targetConn)
    {
        try
        {
            // Retrieve "Friendly Site Name" from IIS for TargetSite
            DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSite);

            FileStream f = new FileStream("c:\\myfile.txt", FileMode.Append, FileAccess.Write);
            StreamWriter w = new StreamWriter(f);
            w.WriteLine("In ConfigureWebConfig stap 1 ");
            w.Close();
            w.Dispose();
            f.Close();
            f.Dispose();

            string friendlySiteName = entry.Properties["ServerComment"].Value.ToString();

            f = new FileStream("c:\\myfile.txt", FileMode.Append, FileAccess.Write);
            w = new StreamWriter(f);
            w.WriteLine("In ConfigureWebConfig friendlySiteName: " + friendlySiteName);
            w.Close();
            w.Dispose();
            f.Close();
            f.Dispose();

            // Open Application's Web.Config 
            Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetVDir, friendlySiteName);
            addConnectionStringAttribute(targetConn, config);

            f = new FileStream("c:\\myfile.txt", FileMode.Append, FileAccess.Write);
            w = new StreamWriter(f);
            w.WriteLine("In ConfigureWebConfig stap 2 ");
            w.Close();
            w.Dispose();
            f.Close();
            f.Dispose();
            // togleCompilationAttribute(config);

            // Persist web.config settings 
            config.Save();

            f = new FileStream("c:\\myfile.txt", FileMode.Append, FileAccess.Write);
            w = new StreamWriter(f);
            w.WriteLine("In ConfigureWebConfig stap 3 ");
            w.Close();
            w.Dispose();
            f.Close();
            f.Dispose();
        }
        catch (Exception)
        {
            throw;
        }

    }

    private static void addConnectionStringAttribute(string connectionStringValue, Configuration config)
    {
        ConnectionStringSettings appDatabase = new ConnectionStringSettings();

        appDatabase.Name = "dataConnectionString"; 
        appDatabase.ConnectionString = connectionStringValue;
        appDatabase.ProviderName = "System.Data.SqlClient";

        FileStream f = new FileStream("c:\\myfile.txt", FileMode.Append, FileAccess.Write);
        StreamWriter w = new StreamWriter(f);
        w.WriteLine("In addConnectionStringAttribute stap 1 ");
        w.Close();
        w.Dispose();
        f.Close();
        f.Dispose();

        config.ConnectionStrings.ConnectionStrings.Clear();
        config.ConnectionStrings.ConnectionStrings.Add(appDatabase);

        f = new FileStream("c:\\myfile.txt", FileMode.Append, FileAccess.Write);
        w = new StreamWriter(f);
        w.WriteLine("In addConnectionStringAttribute stap 2 ");
        w.Close();
        w.Dispose();
        f.Close();
        f.Dispose();
    }
A: 

Maybe this or this will help you.

If it's neither of those causes then the attribute probably doesn't exist.

Edit:

According to this, if you're using Win2k8 you need to enable "The IIS Metabase and IIS6 Configuration Compatibility" if you get this error. It is not automatically installed when the Web Server role is enabled.

Here is a related question.

Sani Huttunen
I have the provider in capitals (IIS)
Martijn
Trim didn't work. Is it possible that the error is in this line: DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSite.Trim()); And then the parameter. I mean if this is a wrong value, does DirectoryEntry generate a error or something?
Martijn
According to other sources: Yes. The some "Unknown error" occurs if the url is wrong.
Sani Huttunen
What OS are you running this on?
Sani Huttunen
MS Windows XP SP3
Martijn
A: 

Check the definition of your input field. The capitalization of the name?

Shiraz Bhaiji
The name of the input field is EDITA1 and in my code i've EDITA1 spelled correct.
Martijn
A: 

Hi

if (m_targetSite.StartsWith("/LM/")) m_targetSite = m_targetSite.Substring(4);

use above code before this :- // Retrieve "Friendly Site Name" from IIS for TargetSite
DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + m_targetSite); m_siteName = entry.Properties["ServerComment"].Value.ToString();