Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
L

luccingolo

@luccingolo
About
Posts
10
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • CREATE DATABASE parameter for FROM master..sysdatabases
    L luccingolo

    Hi Dave, i'm sorry but either you badly misunderstood my question or my english es even worse than i thought. I AM USING SQL 2008 EXPRESS EDITION, nevertheless the code is not working. The best i could get until now is an execution without an error. But in the end, i can't find any "new" (created) .mdf-file on my harddisk??? :confused: Here comes the code.

    Imports System.Data.SqlClient
    Public Class Form1
    Private MyConnection As String

    Private Sub Form1\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        MyConnection = "Integrated Security=SSPI;" + "Initial Catalog=;" + "Data Source=.\\SQLEXPRESS;" 'mydb
    
        Dim mySQL As String = "IF EXISTS (SELECT \* FROM sys.databases WHERE name = 'MyDatabase')" & \_
            "DROP DATABASE \[MyDatabase\];CREATE DATABASE \[MyDatabase\]"
    
        Try
            Dim conn As New SqlConnection(MyConnection)
            Dim myCmd As New SqlCommand(mySQL, conn)
    
            ' Open the connection, execute the command, and close the connection. It is more efficient to 
            '  ExecuteNonQuery when data is not being returned.
    
            If conn.State <> ConnectionState.Open Then conn.Open()
    
            myCmd.ExecuteNonQuery()
            conn.Close()
    
            ' Data has been successfully submitted
    
            MessageBox.Show("New Database has been ' successfully created !", \_
                            " Database Creation Completed", MessageBoxButtons.OK, \_
                            MessageBoxIcon.Information)
        Catch sqlExc As SqlException
            MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", \_
            MessageBoxButtons.OK, MessageBoxIcon.Error)
    
        Catch exc As Exception
            'If mstrConn = MyConnection Then
            '    ' Couldn't connect to SQL Server.  Now try MSDE.
            '    mstrConn = MY\_MSDE\_CONNECTION\_STRING
            '    'Connecting to MSDE
            'Else
            '    ' Unable to connect to SQL Server or MSDE
            '    MessageBox.Show("SQL Or MSDE Connection Failed", \_
            '         "Connection Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error)
            '    End
            'End If
        End Try
    End Sub
    

    End Class

    Any idea of what's wrong here. Thank you in anticipation, Lucchingolo

    Visual Basic database mysql sql-server com sysadmin

  • CREATE DATABASE parameter for FROM master..sysdatabases
    L luccingolo

    Tanks, everything is clear now.:thumbsup:

    Visual Basic database mysql sql-server com sysadmin

  • CREATE DATABASE parameter for FROM master..sysdatabases
    L luccingolo

    Hi Dave, please don't ask about the error message. It is sooo long.(i think that most sql-messages are quite long) ;) So far the Try/Catch bloc tells me it's a "SqlException" My idea was to check if a certain .mdf-file (in this case: MyDatabase.mdf) already exists. If so, it should be deleted (dpopped) to allow the creation of that file. (Of course that makes no sense, it's only for training purpose) I want to learn how to dynamically create a sql-DB with a few tables and its stored procedures. And of course i can not create a new DB(the same one) each time i lounch my application. But in the meantime i think it should be possible to solve this problem with "pure" VB instead of a SQL-command. I will try if i can not solve it with the File.Exists method of the System.IO-namespace. Should work. I hope you have undestood my intentions now. Of course if you have a suggestion or a better idea, i'm interested. Anyhow, in the case "File.Exists" would not work, i will post a new question in this forum. Thanks again for your answer, Lucchingolo

    Visual Basic database mysql sql-server com sysadmin

  • CREATE DATABASE parameter for FROM master..sysdatabases
    L luccingolo

    Hi Luc, i must admit that i made a few mistakes. I'm sorry. When (in the General Database forum) i have been suggested to chage to the VS-forum i did not think of the consequences. I was too much focused on my little problem. And regarding the "formatted code", you are right of course. I promise i will do it better the next time. As english is not my native language, i must admit that i struggle with two of your expressions. 1. What is Q&A? 2. What do you mean by "real forum"? thanks a lot, Lucchingolo

    Visual Basic database mysql sql-server com sysadmin

  • CREATE DATABASE parameter for FROM master..sysdatabases
    L luccingolo

    Hi all I'm experiencing troubles with the code from this site. Which parameter is exspected instead of:"master..sysdatabases" in the following sql-command: Dim mySQL As String = _ "IF EXISTS (" & _ "SELECT * " & _ "FROM master..sysdatabases " & _ "WHERE Name = 'MyDatabase')" & vbCrLf & _ "DROP DATABASE MyDatabase " & vbCrLf & _ "CREATE DATABASE MyDatabase " I'm using sql server 2008 express Thanks, Lucchingolo

    Visual Basic database mysql sql-server com sysadmin

  • create database, which parameter
    L luccingolo

    Thank your, I will give it a try in the Visual Basic forum. I could not find a VS-forum. Guess you meant the VB-forum.

    Database database mysql com

  • create database, which parameter
    L luccingolo

    Sorry, still get an error. Maybe i misundertood you. Fact is that i still get an error. What i did is using your sql-command as string for my SQL-command. What I mean is this: In the Form1_Load-Event of my Application(project). MyConnection = "Server=localhost;" & "DataBase=;" & "Integrated Security=SSPI" 'Your line of code Dim mySQL As String = "IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDatabase')DROP DATABASE [MyDatabase]" Try Dim conn As New SqlConnection(MyConnection) Dim myCmd As New SqlCommand(mySQL, conn) conn.Open() myCmd.ExecuteNonQuery() conn.Close() . . . Last but not least, don't forget that the point is not only to "drop" a Database but i'm trying so hard to create a SQL-Database. :) thank you, Lucchingolo

    Database database mysql com

  • create database, which parameter
    L luccingolo

    I'm using Microsoft SQL Server 2008

    Database database mysql com

  • create database, which parameter
    L luccingolo

    Hi all I'm experiencing troubles with the code from this site. Which parameter is exspected instead of:"master..sysdatabases" in the following sql-command:Dim mySQL As String = _ "IF EXISTS (" & _ "SELECT * " & _ "FROM master..sysdatabases " & _ "WHERE Name = 'MyDatabase')" & vbCrLf & _ "DROP DATABASE MyDatabase " & vbCrLf & _ "CREATE DATABASE MyDatabase " Thanks, Lucchingolo

    Database database mysql com

  • Import Excel columns in existing SQL database
    L luccingolo

    Hi Ted2102, i suppose that your suggested solutions would do for an excel file with known columnnames and a constant number of columns. But that's not my case. The files i want to be able to import will not always have the same number of columns and their columnames will change from file to file. The only thing these files have in common is that they will contain contact informantions, like name, address, telephonenumber... a.s.o. That's why i wanted to be able to assign the columns of the Excel-file manually (in the listboxes of the form) to the ones of my SQL database. I'm sorry for your efforts in helping me, but in the mean time the situation has changed and i have found a nice code snippet which does the kind of work i need. As a beginner in VB i would like to progress in programming. And that's why i think it would be more important to practice a little bit with the technics used in this snippet. So my new question is now: Does anybody have a link to a good tutorial about learning "List(of Type)" and about "LINQ-queries" for beginners? Any link or code-snippet would be appreciated. Thanks for your help

    Visual Basic database help learning
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups