0

i want to create a connection to my database in my application on vb.net i stored a procedure called "CTable" that will create tables if they don't exist

im using this code:

    Dim strConnection As String
    strConnection = "Data Source=Localhost; Initial Calalog=Northwind; Integrated Security=True"
    Dim MyConn As SqlConnection
    Dim cmd As SqlCommand

    MyConn = New SqlConnection(strConnection)
    Dim query As String = "EXEC CTable"

    cmd = New SqlCommand(query, MyConn)

    MyConn.Open()
    cmd.ExecuteNonQuery()
    MyConn.Close()

but he is giving this error: " An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll Additional information: Keyword not supported: 'initial calalog'"

my question is : what should i put in my 'strConnection' variable to be able to execute my CTable Procedure????

3
  • 1
    connectionstrings.com Commented Jul 4, 2013 at 11:10
  • Connection string formats differ between different databases. What database are you trying to connect to? Commented Jul 4, 2013 at 11:10
  • Normal practice is to store your connection string in the web.config file. Commented Jul 4, 2013 at 11:19

3 Answers 3

2

You have a typo in the connection string. Try "Catalog" instead of "Calalog" ;)

Sign up to request clarification or add additional context in comments.

Comments

0

The word is Catalog not Calalog.

So this should work:

strConnection = "Data Source=Localhost; Initial Catalog=Northwind; Integrated Security=True"

Note that you also have to set the CommandType to CommandType.StoredProcedure.

But always use the Using statement to ensure that unmanaged resources are disposed even on error:

Dim strConnection = "Data Source=Localhost; Initial Catalog=Northwind; Integrated Security=True"
Using MyConn = New sqlclient.SqlConnection()
    Using cmd = New SqlClient.SqlCommand("EXEC CTable")
        cmd.CommandType = CommandType.StoredProcedure
        MyConn.Open()
        cmd.ExecuteNonQuery()
    End Using
End Using ' also closes the conection

Comments

0

Standard Security

Data Source=serverName\instanceName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

Trusted Connection

Data Source=serverName\instanceName;Initial Catalog=myDataBase;Integrated Security=SSPI;

2 Comments

hey, now am using this strConnection "Data Source=.\SQLEXPRESS; Initial Catalog= dbCourrier.mdf; Integrated Security=True;user id = Daniel; Password = ******; "
but i still have this error An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Cannot open database "dbCourrier.mdf" requested by the login. The login failed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.