如何用代码实现在应用程序当前目录新建sql server数据库?
RT。我建了两次代码都不行,求大家指教,代码应该如何改我建库的代码是这样子的:
程序代码:
string str = "CREATE DATABASE MyDatabase ON PRIMARY " + "(NAME = MyDatabase_Data, " + "FILENAME = '" + Application.ExecutablePath + "\\MyDatabaseData.mdf'," + "SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " + "LOG ON (NAME = MyDatabase_Log, " + "FILENAME = '" + Application.ExecutablePath+"\\MyDatabaseLog.ldf'," + "SIZE = 1MB, " + "MAXSIZE = 5MB, " + "FILEGROWTH = 10%)";
但出错了,在Application.ExecutablePath处显示:当前上下文不存在名称Application
改为:
程序代码:
string str = "CREATE DATABASE MyDatabase ON PRIMARY " + "(NAME = MyDatabase_Data, " + "FILENAME = Application.ExecutablePath+"+"\\MyDatabaseData.mdf,"+ "SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " + "LOG ON (NAME = MyDatabase_Log, " + "FILENAME = Application.ExecutablePath+" + "\\MyDatabaseLog.ldf," + "SIZE = 1MB, " + "MAXSIZE = 5MB, " + "FILEGROWTH = 10%)";
也不行。