[sql] How to define a Sql Server connection string to use in VB.NET?

How to: connectionString?

Hopefully a simple question, but I am too new to Visual Basic to understand : http://msdn.microsoft.com/en-us/library/d7469at0.aspx...

I am writing an app in VB and trying to connect it to a "Local Database" / "Dataset".

I received help earlier today to get the code listed below and it appears it will work just fine, except I have no idea how to connect my application to my dataset. From the reading I have been doing, it seems the connectionString would be to connect it to a database that was created with SQL Server. ???

On my VB Windows Form Application, I simply did "Add New Item" then "Local Database" and it asked me what type of database model and I selected "Dataset".

I only have two tables and just need to be able to connect to them. Here is the code or at least the idea of what I would like to do. Please help

    Using sqlCon = New SqlConnection(connectionString)
        sqlCon.Open()
        Dim sqlText = "UPDATE appTable SET clickCount + 1 " & _
            "WHERE appName = @name"
        Dim cmd = New SqlCommand(sqlText, sqlCon)
        cmd.Parameters.AddWithValue("@name", appName)
        cmd.ExecuteNonQuery()
    End Using

I am so sorry for this poorly phrased question, I have been reading and trying to learn this for too long and have frustrated myself. I come from Python with a lot less syntax and "rules" and I feel I could be way farther on this project and to be stuck on simply connecting to the "database" has me beyond frustrated :/

Thanks for assistance in advance.

answer : There is an App.config file in my Solution Explorer with the connectionString Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\gadgetDatabase.mdf;Integrated Security=True

This question is related to sql vb.net visual-studio-2012

The answer is


The Connection String Which We Are Assigning from server side will be same as that From Web config File. The Catalog: Means To Database it is followed by Username and Password And DataClient The New sql connection establishes The connection to sql server by using the credentials in the connection string.. Then it is followed by sql command which retrives the required data in the dataset and then we assing them to required variables or controls to get the required task done


Use the following Imports

Imports System.Data.SqlClient
Imports System.Data.Sql

Public SQLConn As New SqlConnection With {.ConnectionString = "Server=Desktop1[enter image description here][1];Database=Infostudio; Trusted_Connection=true;"}

Full string: enter image description here


May it will help for u. U should use (localdb).

LocalDB automatic instance

Server=(localdb)\v11.0;Integrated Security=true;

LocalDB automatic instance with specific data file

Server=(localdb)\v11.0;Integrated Security=true; AttachDbFileName=C:\MyFolder\MyData.mdf;


Set the connection string in your config file:

<connectionStrings>
    <add name="ConnString"
         connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\gadgetDatabase.mdf;Integrated Security=True" />
</connectionStrings>

Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.IO
Imports System.Configuration
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Dim cn As New SqlConnection(connectionString)
Dim cmd As New SqlCommand
Dim dr As SqlDataAdapter

Standard Security:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

Trusted Connection:

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

will be glad if it helps.

Regards.


             if (reader.HasRows)
            {
                while (reader.Read())
                {
                    comboBox1.Items.Add(reader.GetString(0));
                }
            }
            reader.Close();

            MySqlDataReader reader1 = cmd1.ExecuteReader();
            if (reader1.HasRows)
            {
                while (reader1.Read())
                {
                    listBox1.Items.Add(reader1.GetString(0));
                }
            }
            reader1.Close();

Try

Dim connectionString AS String = "Server=my_server;Database=name_of_db;User Id=user_name;Password=my_password"

And replace my_server, name_of_db, user_name and my_password with your values.

then Using sqlCon = New SqlConnection(connectionString) should work

also I think your SQL is wrong, it should be SET clickCount= clickCount + 1 I think.

And on a general note, the page you link to has a link called Connection String which shows you how to do this.


Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to vb.net

How to get parameter value for date/time column from empty MaskedTextBox HTTP 415 unsupported media type error when calling Web API 2 endpoint variable is not declared it may be inaccessible due to its protection level Differences Between vbLf, vbCrLf & vbCr Constants Simple working Example of json.net in VB.net How to open up a form from another form in VB.NET? Delete a row in DataGridView Control in VB.NET How to get cell value from DataGridView in VB.Net? Set default format of datetimepicker as dd-MM-yyyy How to configure SMTP settings in web.config

Examples related to visual-studio-2012

How to actually search all files in Visual Studio Tests not running in Test Explorer How to use _CRT_SECURE_NO_WARNINGS Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0 How can I resolve the error: "The command [...] exited with code 1"? Could not load file or assembly Exception from HRESULT: 0x80131040 MSVCP120d.dll missing How can I change IIS Express port for a site The program can't start because MSVCR110.dll is missing from your computer Controlling execution order of unit tests in Visual Studio