我做了一個C#程序創建的本地主機MS SQL如下數據庫的數據庫時:SQL權限問題產生
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "SERVER = " + serverName + "; DATABASE = master; Integrated Security=SSPI";
string query = " CREATE DATABASE " + dbName + " ON PRIMARY "
+ " (NAME = " + dataFileName + ", "
+ " FILENAME = '" + schemaPath + "', "
+ " SIZE = 2MB,"
+ " FILEGROWTH = 10%) "
+ " LOG ON (NAME =" + logFileName + ", "
+ " FILENAME = '" + logFilePath + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH = 10%) ";
try
{
conn.Open();
SqlCommand sqlCmd = new SqlCommand(query, conn);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("Database has been created successfully!");
}
catch (System.Exception ex)
{
Console.WriteLine("Failed to create the db. " + ex.ToString());
Environment.Exit(1);
}
它可以在我的電腦完全正常,但未能另一臺機器上: 我對我指定的文件夾擁有寫入權限。
無法創建數據庫。 System.Data.SqlClient.SqlException (0x80131904):目錄查找文件 「C:\ Users \ Administrator \ Desktop \ test2.mdf」失敗,操作 系統錯誤5(訪問被拒絕。)。 CREATE DATABASE失敗。某些文件 名稱不能被創建。檢查相關的錯誤。在 System.Data.SqlClient.SqlConnection.OnError(SqlException異常, 布爾breakConnection)在 System.Data.SqlClient.SqlInternalConnection.OnError(SQLEXCEPTION 例外,布爾breakConnection)在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning( )在 System.Data.SqlClient.TdsParser.Run(runBehavior runBehavior, 的SqlCommand cmdHandler,SqlDataReader的數據流, BulkCopySimpleResultSet bulkCopyHandler,TDS ParserStateObject stateObj)在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(字符串 方法名,布爾異步)at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult 結果,字符串methodName中,布爾sendToPipe)維持在 com.appneta.test.DB_DataLoader.createDB(字符串DBNAME System.Data.SqlClient.SqlCommand.ExecuteNonQuery())
任何想法?
我有同樣的問題,在這個問題上的任何進展? – Alex