By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

Create SQL Db on SQL server

P: n/a
Jon
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.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Jon wrote:
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.

Nov 21 '05 #2

P: n/a
Jon
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.

"Robert Porter" wrote:
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

Jon wrote:
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.

Nov 21 '05 #3

P: n/a
In message <A0**********************************@microsoft.co m>, Jon
<Jo*@discussions.microsoft.com> writes
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

--
Andrew D. Newbould E-Mail: ne********@NOSPAMzadsoft.com

ZAD Software Systems Web : www.zadsoft.com
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.