DBUtility项目中的DbHelperSQL.cs (找自己对应的数据库类型) 修改前20行中的数据库连接字符串获取方式为: //数据库连接字符串(web.config来配置),多数据库可使用DbHelperSQLP来实现. // public static string connectionString = PubConstant.ConnectionString; //配置winform的获取方法 public static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); 并在应用层添加app.config <?xml version="1.0"?> <configuration> <configSections> </configSections> <connectionStrings> <add name="ConnectionString" connectionString="Data Source=server;Initial Catalog=Database;User ID=sa;Password=sa" providerName="System.Data.SqlClient"/> </connectionStrings> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> <runtime> <legacyUnhandledExceptionPolicy enabled="true"/> </runtime> </configuration> 还有另一说:动软代码生成器默认是生成asp.net 项目。如果想变成winform程序,需要做到以下几步。 删除web,并添加winform模块。在winform中app.config,添加如下代码:<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> </configSections> <connectionStrings> <add name="ConnectionString" connectionString="Data Source=SUNDAYCAFESQL2005;Initial Catalog=winformTest;User ID=sa;password=aaa" providerName="System.Data.SqlClient" /> </connectionStrings></configuration>改下类PubConstant.cs 中的方法 /// <summary> /// 获取连接字符串 /// </summary> public static string ConnectionString { get { string _connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); return _connectionString; } }<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> </configSections> <connectionStrings> <add name="ConnectionString" connectionString="Data Source=SUNDAYCAFESQL2005;Initial Catalog=winformTest;User ID=sa;password=aaa" providerName="System.Data.SqlClient" /> </connectionStrings>