Create SQL Db on SQL server

G

Guest

Hi,

I have tried to create a new DB on the SQL Server but unsucessful..
I have looked at the microsoft "How to create SQL Database in vb.net", but
it doesn't seems to solve my problem.

below is the connection string that i used to create, but i get error saying
login has fails. I am sure the login works because i can read out data from
the SQL server no problem...

Dim conn As SqlConnection = New SqlConnection("Initial Catalog= NewDB;" & _
"Data Source=SERVER-MACHINE;" & _
"UID=abcde;" & _
"PWD=abcde;"

Dim cmd0 As New SqlClient.SqlCommand("CREATE DATABASE ON PRIMARY " & _
"(NAME = NewDB, " & _
" FILENAME = 'D:\Program
Files\Microsoft SQL Server\MSSQL\Data\" & m_date & ".mdf', " & _
" SIZE = 2MB, " & _
" MAXSIZE = 10MB, " & _
" FILEGROWTH = 10%) " & _
" LOG ON " & _
"(NAME = " & m_date & "_log,
" & _
" FILENAME = 'D:\Program
Files\Microsoft SQL Server\MSSQL\Data\" & m_date & ".ldf', " & _
" SIZE = 1MB, " & _
" MAXSIZE = 5MB, " & _
" FILEGROWTH = 10%) ", conn)

so i wonder m i doing anything wrong???
Any help would be appreciated.

many thanks.
 
R

Robert Porter

To start with, the Initial Catalog can't point to a database that does
not yet exist. Use "master".

Secondly, once you create the database you will have to grant the user
permissions to access the database before you can then log into it.

Hope this helps....

Bob
 
G

Guest

Thankyou Robert, so i just make "Initial Catalog=master"?

and could you mind explain more a bit how to grant the user permission in
code?

many thanks in advance.
 
A

Andrew D. Newbould

Jon said:
Hi,

I have tried to create a new DB on the SQL Server but unsucessful..
I have looked at the microsoft "How to create SQL Database in vb.net", but
it doesn't seems to solve my problem.

below is the connection string that i used to create, but i get error saying
login has fails. I am sure the login works because i can read out data from
the SQL server no problem...

Dim conn As SqlConnection = New SqlConnection("Initial Catalog= NewDB;" & _
"Data Source=SERVER-MACHINE;" & _
"UID=abcde;" & _
"PWD=abcde;"

Dim cmd0 As New SqlClient.SqlCommand("CREATE DATABASE ON PRIMARY " & _
"(NAME = NewDB, " & _
" FILENAME = 'D:\Program
Files\Microsoft SQL Server\MSSQL\Data\" & m_date & ".mdf', " & _
" SIZE = 2MB, " & _
" MAXSIZE = 10MB, " & _
" FILEGROWTH = 10%) " & _
" LOG ON " & _
"(NAME = " & m_date & "_log,
" & _
" FILENAME = 'D:\Program
Files\Microsoft SQL Server\MSSQL\Data\" & m_date & ".ldf', " & _
" SIZE = 1MB, " & _
" MAXSIZE = 5MB, " & _
" FILEGROWTH = 10%) ", conn)

so i wonder m i doing anything wrong???
Any help would be appreciated.

many thanks.

Check BOL for the CREATE DATABASE command because yours is NOT correct.
For Example:

CREATE DATABASE [MyNewDB] ON (NAME = N'MyNewDB_Data', FILENAME =
N'C:\Program Files\Microsoft SQL Server\MSSQL\data\MyNewDB_Data.MDF' ,
SIZE = 4, FILEGROWTH = 10%) LOG ON (NAME = N'MyNewDB_Log', FILENAME =
N'C:\Program Files\Microsoft SQL Server\MSSQL\data\MyNewDB_Log.LDF' ,
SIZE = 1, FILEGROWTH = 10%) COLLATE SQL_Latin1_General_CP1_CI_AS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top