Michael, I thought SQL conventions dictated all upper case and not camel case as you suggested, anyway, can you please repost your create statement as I tried a few combinations and none worked. Something is up and I don't think its the create statement.
Here's my current code, have a look:
<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="System.Data" %> <% @Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(o as Object, e as EventArgs)
Dim ConnectionString As String = "Server=localhost;Database=master;User ID=********;Password=********;"
Dim myConnection As New SqlConnection(ConnectionString)
Dim db_Name As String = "db_MLH"
Dim strSQL As String = "Create Database " & db_Name & ";"
Dim myCommand As New SqlCommand(strSQL, myConnection)
myConnection.Open()
myConnection.Close()
lblStatus.Text = "DB created"
End Sub
</script>
<asp:label id="lblStatus" runat="server" /> |
Can anyone try this code to create a SQL server database? Even on 'borgs' code of these forums, he asks people to create a database and his not doing it from code.
There's a few things I don't know;
1. The user will connect to the 'master' db what about if he doesn't have access to it? I gave the user access anyway for testing, of no avail. Do I realy have to connect to 'master' to create another db?
2. My connection string, I tried both types; 'data source' and 'server' which one is the correct one?
3. Is my db open/close approach correct for this purpose?
4. How do I get to know/see/catch errors in the connection?
Thanks guys.