?
Solved

An attempt to attach an auto-named database for file

Posted on 2006-05-12
7
Medium Priority
?
1,395 Views
Last Modified: 2012-06-22
Using Create Database in SQL Server 2005 Express from within VB, I apparently was successful on the first try.

On the second try I got the widely-posted-about "An attempt to attach an auto-named database for file..." error.

I'm now going to try to research that.

Any shortcuts to the solution would be greatly appreciated.

Thanks!
0
Comment
Question by:codequest
  • 5
  • 2
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16671334
How are you creating the database?

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16671407

on the first try (which worked, but may have created the problem), I used the function below with these two values

wrkCreateDBString = "Create Database TempDB"

varConnString = "DataSource= .\SQLEXPRESS;AttachDbFilename="(path to my development directory)\CurrentDevelopmentDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

'========================
 Public Sub CreateTempDatabase(ByVal varUUID, ByVal varConnString)
        Dim wrkCreateDBString = Me.CTQ_TempDatabase_QS(varUUID)
        '------------------------
        Try
            Using wrkConnection As New SqlConnection(varConnString)
                Dim wrkSQLCmd As New SqlCommand(wrkCreateDBString, wrkConnection)
                wrkSQLCmd.Connection.Open()
                wrkSQLCmd.ExecuteNonQuery()
            End Using
        Catch ex As Exception
            Debug.WriteLine(Err.Description)
        End Try
    End Sub
'============================

'---------------
(In retrospect the connection string doesn't make any sense, since it was pointing at an existing database....how do you create a connection string for a new database?  I'll put up another post on that.)
'---------------
I subsequently found how to put the physical location variables in the create string, but must get around the current problem first.
'---------------
0
 
LVL 2

Author Comment

by:codequest
ID: 16671682
More info

'==========================
If I change the name of the "to be created" file, the error comes up with that name

'==========================

per posted suggestions, ran:

C:\SSEUtil.exe -l
1. master
2. tempdb
3. model
4. msdb
5. (currentdevelopmentpath & file).MDF

the "unwanted database" is not there.

'==============================

tried deleting ////SQLExpress per

http://sqljunkies.com/WebLog/ktegels/archive/2005/11/15/17401.aspx

didn't work

'==============================

tried deleting "User Instance=True"  from connection string per

http://www.aspspider.com/resources/Resource170.aspx

didn't work, put it back

'==============================

wondering if this goes back to bad connection string, attempting to make a connection with a database that isn't there yet, in order to execute a sql command to create that database...


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:codequest
ID: 16671752
So I manually built the database, assuming there will be a solution to the create problem.

VS2005 didn't have any problem creating the SQL DB.

Now I'm getting the same error, with the error referencing the database name in the connection string (which is slightly different),
when I try to do a file create

'==================================
 Private Sub CreateSQLTable(ByVal varTableName, ByVal varConnectionString)
        '------------------------
        Dim wrkCreateTableString = Me.CTQ_Control_QS(varTableName)
        '------------------------
        'Debug.Print(wrkCreateString)
        Try
            Using wrkConnection As New SqlConnection(varConnectionString)
                Dim wrkSQLCmd As New SqlCommand(wrkCreateTableString, wrkConnection)
                wrkSQLCmd.Connection.Open()
                wrkSQLCmd.ExecuteNonQuery()
            End Using
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
        '------------------------
    End Sub
===============================

I was able to run this routine to create tables in the existing database with no problem, even as this issue existed with the new create database


0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16672284
This is a class that uses SMO that you can use to add/remove databases:

' Add a reference to Microsoft.SqlServer.Smo to the project.

Imports Microsoft.SqlServer.Management
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common

Public Class SqlServer2005

  Public Shared Sub AddDatabase(ByVal serverName As String, ByVal databaseName As String)

    Dim server As New Server(serverName)

    Dim database As New Database(server, databaseName)

    database.Create()

  End Sub

  Public Shared Sub DropDatabase(ByVal serverName As String, ByVal databaseName As String)

    Dim server As New Server(serverName)

    Dim database As Database = server.Databases(databaseName)

    database.DropBackupHistory()
    database.Drop()

  End Sub

End Class

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16674538
Thanks for the post.  I've got some approaches based on connectionstring...if that doesn't work I'll see if this fits the situation.
0
 
LVL 2

Author Comment

by:codequest
ID: 16722279
Must have been something with connection strings, because when I fiddled there, I got it to work.  Thanks for the suggestions...they were educational and helped keep me focused.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question