日期:2014-05-18 浏览次数:20722 次
string connString = @"server=.\sqlexpress;user id=sa;password=123"; SqlConnection myConn = new SqlConnection(connString); 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%)"; SqlCommand myCommand = new SqlCommand(str, myConn); try { myConn.Open(); myCommand.ExecuteNonQuery();
System.Data.SqlClient.SqlException: 对文件 "C:\Documents and Settings\Tansion\桌面 \create database\WindowsFormsApplication1\WindowsFormsApplication1 \bin\Debug\WindowsFormsApplication1.EXE\MyDatabaseData.mdf" 的目录查找失败,出现操作系统错误 123(文件名、目录名或卷标语法不正确。)。 CREATE DATABASE 失败。无法创建列出的某些文件名。请查看相关错误。 在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) 在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) 在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 在 WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Documents and Settings\Tansion\桌面\create database\WindowsFormsApplication1 \WindowsFormsApplication1\Form1.cs:行号 55
myCommand.ExecuteNonQuery();