473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create SQL Db on SQL server

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
3 2249
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
22
by: dw | last post by:
Please help some desperate developers!! We need to create an ASP.NET project via VS.NET 2003 on a networked Win 2003 server that we use for testing, but it keeps generating an error: "The Web...
4
by: jaredea | last post by:
I have the following setup: SBS 2003 Server Windows 2003 Enterprise Server (setup as an Application Server) Windows XP Pro Desktop Both the Application server and desktop have Visual Studio...
10
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung...
3
by: fyi85 | last post by:
I am trying to create a server on the same machine running the same instance. This is v8.1.5 on Windows 2003 Server. The instance is set to FEDERATED=YES The server will be created for database...
3
by: zgh1970 | last post by:
Hi, All, We have a database on db2 udb aix. The database has federated server to db2 mainframe. Now We have already catalog database of db2/400 on the db2 UDB aix server. I tried to create new...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
4
by: John Straumann | last post by:
Hello all: Most of my development for websites has been on test VPC images where VS is installed on the server image. I now have a setup where I have a test server joined to my domain, and a...
10
by: AAaron123 | last post by:
I want to create a database with one table on the host. I can't user SQL Server Management Studio to do it so I guess I have to do it programmatically. I have in mind that in the session start...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.