在学习FileNet P8 中的PE API的时候,接触到SQL2000和SQL2005的不同连接字符串。按照教材上所给出的SQL2000的连接字符串和SQL2005的驱动jar包是不匹配的。
去年年底在廊坊市政府门户网站机房里,也遇到过这样的一个问题。那是在config文件中,涉及到的数据库连接字符串的问题。
SQL2000:
驱动:com.microsoft.jdbc.sqlserver.SQLServerDriver
URL: jdbc:microsoft:sqlserver://localhost:1433;databaseName=***
-----
SQL2005:
驱动:com.microsoft.sqlserver.jdbc.SQLServerDriver
URL:jdbc:sqlserver://localhost:1437;databaseName=***
在API操作过程中,这样使用SQL2005 JDBC Driver。
Connection conn = DriverManager .getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=***", "username", "password");
----
VS通常将数据库的连接字符串设置在Webconfig中添加连接字符串键设置如下:
SQL2000:
webconfig添加键: <configuration> <appsettings> <add key="SQLConnection" value="data source.;database=DB;user id=sa;password= "/> </appsettings> </configuration> 程序调用:string connectionstring=ConfigurationSetting.Appsettings["SQLConnecton"]
SQL2005:
webconfig设置: <configuration xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0> <connectionStrings> <add name="NorthwindConnectionString"; connectionString="DataSource=.;Initial Catalog=Northwind; User ID=sa;Password= "providerName="System.Data.SqlClient"/> </connectionStrings> </configuration> 程序调用:string conn = WebconfigurationManager.ConnectionStrings["NorthwindconnectionString"].connectionString; ASP.NET 2.0连接字符串的设置是通过WebConfigurationMannager来管理的,它属于System.Web.Configuration命名空间.