I want to create a database by C# code and I want t开发者_StackOverflow社区o authenticate it with SQL Server (I mean I want to define username and password for it)
How can I do that?
It really is a two step process and it also depends on the security of your SQL Server box. For instance, is SQL Server configured to use mixed mode authentication or windows authentication? Once you find that out, you will know why you are getting this error, its a security error. The user used to create the db should have db admin rights on the db server. If you plan to use windows authentication, have that user be part of the sysadmin group on the db server or at least give him / her rights to CREATE.
Once you take care of your security measures it is a simple process to create a user inside of this db.
精彩评论