使用 ReportDocument 类的 SetDatabaseLogon() 方法

在 ConfigureCrystalReports() 的两行代码之间,调用 NorthwindCustomers 实例的 SetDatabaseLogon() 方法,并将以下某一组参数传递给该方法:

  1. 用您的用户名和密码调用 SetDatabaseLogon() 方法。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/8yfdxzdx.alert_note(zh-cn,VS.90).gif" alt="Note" class="note" />注意</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>出于安全性考虑,使用访问权限受到限制的数据库帐户非常重要。有关更多信息,请参见<a href="ms227498(v=vs.90).md">“安全性:创建受限访问数据库帐户”</a>。</p></td>
</tr>
</tbody>
</table>

在编写的代码中,用自己的密码代替示例密码 1234(如下所示)。

``` vb
northwindCustomersReport.SetDatabaseLogon("limitedPermissionAccount","1234")
```

``` csharp
northwindCustomersReport.SetDatabaseLogon("limitedPermissionAccount","1234");
```
  1. 或者用您的服务器名、数据库名、用户名和密码调用 SetDatabaseLogon() 方法。

    Note注意

    此方法不能更改服务器或数据库。只能使用在报表中指定的默认服务器和数据库。

    出于安全性考虑,使用访问权限受到限制的数据库帐户非常重要。有关更多信息,请参见“安全性:创建受限访问数据库帐户”

    在编写的代码中,用自己的密码代替示例密码 1234(如下所示)。

    northwindCustomersReport.SetDatabaseLogon("limitedPermissionAccount","1234", "ServerName", "Northwind")
    
    northwindCustomersReport.SetDatabaseLogon("limitedPermissionAccount","1234", "ServerName", "Northwind");