seehttp://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q186/2/46.asp&NoWebContent=1

解决方案 »

  1.   

    saucer(思归, MS .NET MVP):
    我看了你给我的网址,里面写的例子只有两个参数,那第三个参数怎么写呢,
    有没有个C#的例子,返回数据库所有表的
      

  2.   

    in C#, don't use ADO, use ADO.NET instead, see
    http://expert.csdn.net/Expert/topic/1333/1333347.xml?temp=6.878078E-03
      

  3.   

    from the documentation, the last parameter:SchemaID 
    This optional parameter specifies the GUID for a provider-schema schema query not defined by the OLE DB specification. This parameter is required if the QueryType parameter is set to adSchemaProviderSpecific; otherwise, it is not used. This parameter is not supported by the OLE DB Provider for AS/400 and VSAM. 
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/his/htm/_sna_openschema_method_oledb.asp
      

  4.   

    con.OpenSchema(ADODB.SchemaEnum.adSchemaTables,
                   new object[]{null,null,null,"TABLE"} ,null);
    可是我现在这样写,编译能够通过,运行时报
    "参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。"
      

  5.   

    Problems with C# 
    Because ADO MD relies heavily on schema rowsets, you need to be able to fully utilize the OpenSchema method. Other than MDX, OpenSchema is the only mechanism that ADO MD provides to retrieve the contents of the schema rowset tables. Unfortunately, the OpenSchema method is difficult to call from a .NET language such as C# because of the complexity of the OpenSchema parameters. Two factors create this complexity: The parameters are optional, and the criteria parameter is an array. Each of these factors creates a problem when you try to integrate .NET and COM.OpenSchema is designed so that you call it with one, two, or three parameters, as the following example calls show:OpenSchema QueryType
    OpenSchema QueryType, Criteria
    OpenSchema QueryType, Criteria, SchemaID
    However, in C# you can't issue the first two of these calls because you can't omit parameters—even when they're declared optional in the COM type library. This restriction is part of C# syntax. In other functions that take optional parameters, this type of restriction isn't a problem because you can issue the call with all parameters, passing default values for any parameters you would have omitted if the language had supported optional parameters (like VB does). But with OpenSchema, passing default parameters is difficult and risky because the values for the SchemaID parameter aren't available in the ADO MD type library. You'd have to determine what the default value for SchemaID is and declare the equivalent value in C#. Using SchemaID's default value is risky because a future version of ADO MD could change the values of these constants, and your code would no longer work because its declaration would contain an old value. The methods I used to solve these problems don't include redeclaring any ADO MD SchemaID constants in C# that could possibly change in the future. Let's look at each of the two problems you face with OpenSchema.Solving Integration Problems 
    First, let's look at how to deal with the problem of OpenSchema's optional parameters. As I just explained, C# doesn't support omitting parameters, and the values for the third parameter, SchemaID, aren't included in the ADO MD type library. Thus, you have to determine an innovative way to call OpenSchema. To omit a parameter, you have to take advantage of late binding. Usually, binding takes place during a program's compilation, but late binding means that a method call and its parameters aren't validated against its definition until runtime. Listing 1 shows an example of how to use late binding with only one parameter to call the Open method on the Connection object. The example works because the InvokeMember method in the .NET runtime library can determine how to issue a method call with some parameters omitted, which the C# compiler can't do. Calling the Open method with just a connection string is convenient because you rarely use other parameters (e.g., UserID, Password, Options) with Analysis Services. The UserID and Password parameters are typically unnecessary because Analysis Services uses Windows authentication to determine the identity of the client application.The use of InvokeMember() in Listing 1 deserves an explanation. InvokeMember() is a flexible and powerful method that lets you perform late binding to access an object property (e.g., GET or SET) or lets you call a method in which the structure of the call is determined at runtime. Because ADO and ADO MD support retrieval of type information about the available methods, parameters, and properties at runtime, InvokeMember() can determine how to package the parameters you provide it so that it creates the correct call to the Open method on the Connection object.The InvokeMember method is available on each Type object in .NET. Don't confuse a Type object with an object of a particular type. A Type object in .NET contains information about the type but isn't an instance of the type. (The fourth parameter of InvokeMember, Conn in Listing 1, is the instance of the type on which you issue the method call.)The first parameter of InvokeMember, Open in Listing 1, is the name of the method or property to be accessed. The second parameter, BindingFlags.InvokeMethod, tells InvokeMember what type of operation you want performed. In the example that Listing 1 shows, you want InvokeMember to invoke a method. The third parameter is the binding object. If you pass NULL as the third parameter, as Listing 1 shows, you get the default binding object. The binding object controls the manner in which the .NET runtime library accesses the object (which is the fourth parameter, Conn). Finally, the fifth parameter, new Object[], is the list of parameters that you pass to the method. I could have added multiple items to the array to pass more parameters to the method, but instead I passed an array containing just the connection string.The second problem you encounter when you issue method calls to OpenSchema is figuring out how to declare and construct the Criteria parameter in C#. When I was trying to integrate my COM applications with .NET, I encountered this problem because I didn't have any examples of how to declare the elements of the criteria array in C#. Usually, you can use the Visual Studio .NET object browser to see a parameter's type. But in this case, the types can change with different calls to OpenSchema (depending on what restrictions you want to use) and the parameters are nested inside an array—the object browser doesn't show types inside an array parameter. C#'s data types aren't exactly the same as those in COM, so to match the parameters in a COM method call correctly, you need to know how the COM interoperability layer in .NET will translate the .NET data types into COM data types. Unfortunately, if you get the data types wrong, you get a generic error message that doesn't give you a clue about how to fix the problem. In COM, the Criteria parameter is a safe array of BSTR variants; you'd never need to know that information if you used ADO MD from VB 6.0. You can pass a regular VB array to OpenSchema, and it just works. Explaining a safe array of BSTR variants is beyond the scope of this article, but I'll demonstrate how to define the equivalent criteria array in .NET.
    LISTING 1: Code That Omits Optional Parameters in the Open Method
    Conn = new ADODB.ConnectionClass();
    ADODB.Recordset Rs;
    Object ob=new Object();
    string connectionString =
          "Provider=" + Provider + ";" +
          "Data Source=" + Server;try
    {
          // Use late binding to issue an Open method.
          ob=Conn.GetType().InvokeMember(
                "Open",
                BindingFlags.InvokeMethod,
                NULL,
                Conn,
                new Object[] { connectionString } );      
    }
    catch (Exception e)
    {
        .... 
        string ErrorString = e.Message;
    } Rs=(ADODB.Recordset)ob;while(Rs.EOF)
    {
        .....
       Rs.MoveNext();
    }
    Conn.Close();
      

  6.   

    我的一段代码如下:
    string  dsn="Data Source=" + combo_DSN.Text + ";UID=" + UserName.Text + ";PWD=" + Password.Text +";"; ADODB.Connection con=new ADODB.Connection();
    try{
         con.Open (dsn,"","",0); }
     catch( Exception e1){
        MessageBox.Show (e1.Message );
        return;}ADODB.Recordset rs;
    Object aa=new Object ();
    Object ob=new Object ();
    // Use late binding to issue an Open method.
    ob=con.GetType ().InvokeMember (
    "OpenSchema",
    System.Reflection .BindingFlags.InvokeMethod,
    null,
    con,
    new Object[] { ADODB.SchemaEnum.adSchemaTables ,new Object[]{null,null,null,"TABLE"}} );rs=(ADODB.Recordset )ob;
    while(!rs.EOF)
    {
    aa=rs.get_Collect(2);  // 获取表名称,详细的index号内容察看
                                    // ADODB.SchemaEnum.adSchemaTables查询
                                   // 类型返回字段 
             TableList.Items.Add(aa);
    rs.MoveNext();
    }
    con.Close ();