Jump to content

SQL Problems in VB.NET

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
hbombhazza

hbombhazza

    Newbie

  • Members
  • Pip
  • 1 posts
Hey guys,
First time posting on this forum... I need some help.

As an introduction to my AS Level course I've been working on a banking system. (Simple Transaction with SQL Server.)

I can't find anything wrong... but it's constantly giving the same error...

Here's the short error version:

Quote

An attempt to attach an auto-named database for file E:\Computing\Banking.sdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Here's the long error version:

Quote

System.Data.SqlClient.SqlException was unhandled
Class=14
ErrorCode=-2146232060
LineNumber=65536
Message="An attempt to attach an auto-named database for file E:\Computing\Banking.sdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
Number=15350
Procedure=""
Server="\\.\pipe\91507E49-5FE5-4F\tsql\query"
Source=".Net SqlClient Data Provider"
State=1
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at WindowsApplication1.frmBanking.Form1_Load(Object sender, EventArgs e) in E:\Computing\prjDatabase\prjDatabase\Form1.vb:line 87
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

And finally, here is the source code concerned:
I have bolded the line that VB Express highlights when giving the error:

Quote

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Purpose: Make a Connection to the database and fill a DataSet with the Account and AccountTrans records
' Create memory cell to store the drive letter of the USB drive
Dim DriveLetter As Char
' Get the first character, i.e. the drive letter, from the application's StartupPath
DriveLetter = Application.StartupPath.Substring(0, 1)
' Assign the ConnectionString to give access to the database
conBank.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename="& DriveLetter &":\Computing\Banking.sdf; Integrated Security=True;User Instance=True"
' Create an SqlCommand object to use the DataAdapter for the Account table to retrieve its records from the database into the DataSet
dtaadpAccount.SelectCommand = New SqlCommand
' Assign the Connection object to the DataAdapter so it knows what database to retrieve the records from
dtaadpAccount.SelectCommand.Connection = conBank
' Create a query which will retrieve no records from the Account table but will
' add a table to the DataSet with the same fields
dtaadpAccount.SelectCommand.CommandText = "SELECT * FROM Account WHERE AccountNo = 0"
' Execute the SqlCommand to fill a table called Account in the DataSet
dtaadpAccount.Fill(dtasetBank, "Account")
'TODO: This line of code loads data into the 'BankingDataSet.AccountTrans' table. You can move, or remove it, as needed.
Me.AccountTransTableAdapter.Fill(Me.BankingDataSet.AccountTrans)
'TODO: This line of code loads data into the 'BankingDataSet.Account' table. You can move, or remove it, as needed.
Me.AccountTableAdapter.Fill(Me.BankingDataSet.Account)
' Record that screen objects are to be read only
ViewOnly = True
' Call the Protect procedure to make the screen objects read only
Protect()

End Sub

Any help would be really appreciated... I'm completely stuck :(

#2
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
There could be many reasons for your error.

The easiest way to troubleshoot this is to manually
create a SYSTEM Data Source using the SQLExpress driver.
This should give you some kind of "TEST" button to
verify your ability to connect to the DB in question.

Dynamically attaching a database location/file is cool,
I'm not able to do that with the full blown SQL Server.