tags:

views:

592

answers:

2

Hi all

Using a connection string of

"Provider=SQLOLEDB;Data Source=localhost;User ID=foo;password=bar;Database=CodeLists;Pooling=true;Min Pool Size=20;Max Pool Size=30;"

I get the following stack trace

System.Data.OleDb.OleDbException: No error message available, result code: -2147024770(0x8007007E). at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open()

I get this error even if I change the server URL from localhost to hkfjhuidhf which is invalid, so I assume it's an issue on the server with respect to OleDb connection/setup and/or the MDAC.

The server is Windows Server 2003 running the latest service pack and the MDAC is 2.8 SP2.

The code I'm using is:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void run_Click(object sender, EventArgs e)
    {
        output.Text = string.Empty;
        try
        {
            OleDbConnection connection;
            try
            {
                connection = new OleDbConnection(conString.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error creating connection");
                put(ex.ToString());
                return;
            }

            OleDbCommand command;
            try
            {
                command = connection.CreateCommand();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error creating command");
                put(ex.ToString());
                return;
            }

            command.CommandType = CommandType.Text;
            command.CommandText = "select top 10 * from " + table.Text;

            if (connection.State != ConnectionState.Open)
                connection.Open();

            OleDbDataReader reader;

            try
            {
                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    string @out = string.Empty;
                    while (reader.Read())
                    {
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            @out += reader[i] + ", ";
                        }
                    }
                    put(@out);
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                put(ex.ToString());
            }
            finally
            {
                connection.Close();
            }
        }
        catch (Exception ex)
        {
            put(ex.ToString());
        }

    }

    private void put(string message)
    {
        output.Text += message+Environment.NewLine;
    }
}

And this falls over at the connection.Open()

Does anyone have any ideas? I've reinstalled MDAC from the inf file, however I've read some articles slating SP2 of MDAC 2.8 with regards to .Net code.

Any and all input is extremely welcome.

A: 

If you are connecting to SQL you should use SqlClient:

var conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = connectionString;
conn.Open();

As already suggested, try replacing your Data Source param with "MyServer\SQLExpress". The error could be occurring because it can't find the SQL instance.

James
This isn't an option unfortunately - we moved from using MDB files to hosting the DB on the SQL server due to locking issues with the Access files. This code has shipped and works fine on 99% of our customers, just one is getting the error stated. I've written the above code to verify the issue, however I need to fix the underlying issue on the server rather than fixing the code.
Antony Koch
+1  A: 

It sounds like one or more of the OLEDB components is missing or broken.

When I had a similar problem, I found that reinstalling MDAC didn't work - something which the first install did prevented subsequent reinstalls from fixing missing references/files.

I ended up fixing it by using RegMon to find the failing registry calls, then comparing the keys on which calls failed to a working machine. This will give you a pointer to a missing DLL. I ended up manually re-registering and editing registry entries for 5 or 6 DLLs before I got it working.

It might be worth also asking on serverfault.

Ed Harper
Good suggestion re regmon - I'll give it a go
Antony Koch
This was pretty close - filemon identified that COMSVCS.dll was registered in a location in which the dll was no longer present. Copying the file in there made it work.No one has a clue why it was deleted but we're all up and running now - thanks for all your replies!
Antony Koch