Search code examples
c#sql-serverdatabasemdf

set sql database name with an alphanumeric phrase - C#


I'm trying to make a simple thing but it has become difficult as I do not understand why I proves a mistake like that, I'll explain , I would like to set the database name as well : "FD65F10A-0F6F-487C-A5E4-18A783DC18AE" (PID variable)

But if I leave this , I get this error :

enter image description here

the problem seems to be the hyphen , because if I remove it and septum so : FD65F10A0F6F487CA5E418A783DC18AE everything works , saves me the db and I can go way on the debug..Come I can use the hyphen ? you need to use it , I have to find a solution . Thank you


Solution

  • Not only is the database name failing, but also your LOG ON line.

    Put square brackets around the database name and around the log name:

    "CREATE DATABASE [" + PID + "] ..."
    ...
    "LOG ON (NAME = [" + PID + "Log_Log] ..."