Help SQL
Jan 21, 2013 at 2:34pm UTC
Hello all,
I've got a big problem creating my database. I don't know why it doesn't work. When I write the path directly in the CommandText it creats the database
1 2 3 4 5 6 7 8 9
SqlCommand ^CreateDatabase = gcnew SqlCommand();
CreateDatabase->Connection=Verbindungsaufbau::myConnection;
CreateDatabase->CommandText="CREATE DATABASE PerPlus ON PRIMARY"
+"(NAME = PerPlus_dat, FILENAME = 'C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\DATA\\PerPlus.mdf',"
+"SIZE = 100, MAXSIZE = 200, FILEGROWTH = 10%) LOG ON"
+"(NAME = PerPlus_log, FILENAME = 'C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\DATA\\PerPlus.ldf',"
+"SIZE = 100, MAXSIZE = 200, FILEGROWTH = 10%)" ;
CreateDatabase->ExecuteNonQuery();
, but when I use the value for the filename it doesn't work.
1 2 3 4 5 6 7 8 9 10 11 12 13
SqlCommand ^CreateDatabase = gcnew SqlCommand();
CreateDatabase->Connection=Verbindungsaufbau::myConnection;
CreateDatabase->CommandText="CREATE DATABASE PerPlus ON PRIMARY"
+"(NAME = PerPlus_dat, FILENAME = @test,"
+"SIZE = 100, MAXSIZE = 200, FILEGROWTH = 10%) LOG ON"
+"(NAME = PerPlus_log, FILENAME = @test1,"
+"SIZE = 100, MAXSIZE = 200, FILEGROWTH = 10%)" ;
CreateDatabase->Parameters->AddWithValue("@test" , Pfad_PrimaryFile);
CreateDatabase->Parameters->AddWithValue("@test1" , Pfad_LogFile);
CreateDatabase->ExecuteNonQuery();
In Pfad_PrimaryFile is
"C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\PerPlus.mdf"
and in Pfad_LogFile is
"C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\PerPlus.ldf"
Greetings Bert
Last edited on Jan 26, 2013 at 4:13pm UTC
Jan 21, 2013 at 9:55pm UTC
Use code tags and format the source code.
Seeing the gcnew "keyword" shows that you are using C++/CLI (CLR), in other words .NET and more specific the ADO.NET part (SqlCommand gave it away).
Note: C++/CLI is not standard C++!
Topic archived. No new replies allowed.