SQL Server : database connection with textbox values

xeLin xel

I'm trying to make a application that connect to a SQL Server database with connection values from textbox but when I try connect it gives me connection error

error code: 40 - Could not open a connection to SQL server

Here is the source of the application:

private void ConnectToSQL() {
   string connectionString = @"Data Source=" + textBox4.Text + "Initial Catalog=" + textBox1.Text +"User ID=" + textBox2.Text + "Password=" + textBox3.Text;
using (SqlConnection objSqlConnection = new SqlConnection(connectionString)) {
    try {
        objSqlConnection.Open();
        objSqlConnection.Close();
        MessageBox.Show("Connection is successfull");
    } catch (Exception ex) {
        MessageBox.Show("Error : " + ex.Message.ToString());
    }

Please help me with this issue.

Thank you!

sarwar026

You have missed a semicolon(;) in your connection string. If you append it in your connection string, it should work.

string connectionString = @"Data Source=" + textBox4.Text + 
                           ";Initial Catalog=" + textBox1.Text +
                           ";User ID=" + textBox2.Text + 
                           ";Password=" + textBox3.Text;

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

sql local database connection

분류에서Dev

Simple SQL Server Insert - Many Comma Delimited Values from Textbox to ONE Column

분류에서Dev

Display SQL database colums/rows in a vb textbox

분류에서Dev

SQL Server 2008 connection error

분류에서Dev

Updating SQL Database Using VBA ADODB Connection

분류에서Dev

C# connection to SQL database error

분류에서Dev

Database SQL queries, compare values

분류에서Dev

Changing default database in RODBC for sql server database

분류에서Dev

network connection error in creating sql database from App-Data

분류에서Dev

Exporting Database To Remote SQL Server Instance?

분류에서Dev

Populating the Condition of IF statement from a database in SQL Server

분류에서Dev

populate database from sql server generated script

분류에서Dev

Microsoft SQL Server database character conversion

분류에서Dev

How to import huge blob into SQL Server database?

분류에서Dev

VB.NET How to get row values from database to textbox (multiline)

분류에서Dev

SQL Server 2012 Pivot Dynamic with Values?

분류에서Dev

add values depending on a condition sql-server

분류에서Dev

Remove duplicate values in a cell SQL Server

분류에서Dev

Microsoft SQL Server 2014 over network. Oledb Connection String

분류에서Dev

How to change SQL Connection string from server to Windows authentication

분류에서Dev

Azure SQL Database의 SSRS (SQL Server Reporting Service)

분류에서Dev

vb.net Filling Textbox On combobox Selected Index Changed with SQL Database

분류에서Dev

Textbox Array connected MySQL database

분류에서Dev

Connection to database using XAMPP

분류에서Dev

ERROR 1045: Transferring SQL database from one server to another

분류에서Dev

How to create SQL Server 2012 database with C#?

분류에서Dev

how can we change the date format of SQL Server(2008) Database?

분류에서Dev

How can I change properties of FK in SQL Server database project?

분류에서Dev

Drop all objects in SQL Server database that belong to different schemas?

Related 관련 기사

  1. 1

    sql local database connection

  2. 2

    Simple SQL Server Insert - Many Comma Delimited Values from Textbox to ONE Column

  3. 3

    Display SQL database colums/rows in a vb textbox

  4. 4

    SQL Server 2008 connection error

  5. 5

    Updating SQL Database Using VBA ADODB Connection

  6. 6

    C# connection to SQL database error

  7. 7

    Database SQL queries, compare values

  8. 8

    Changing default database in RODBC for sql server database

  9. 9

    network connection error in creating sql database from App-Data

  10. 10

    Exporting Database To Remote SQL Server Instance?

  11. 11

    Populating the Condition of IF statement from a database in SQL Server

  12. 12

    populate database from sql server generated script

  13. 13

    Microsoft SQL Server database character conversion

  14. 14

    How to import huge blob into SQL Server database?

  15. 15

    VB.NET How to get row values from database to textbox (multiline)

  16. 16

    SQL Server 2012 Pivot Dynamic with Values?

  17. 17

    add values depending on a condition sql-server

  18. 18

    Remove duplicate values in a cell SQL Server

  19. 19

    Microsoft SQL Server 2014 over network. Oledb Connection String

  20. 20

    How to change SQL Connection string from server to Windows authentication

  21. 21

    Azure SQL Database의 SSRS (SQL Server Reporting Service)

  22. 22

    vb.net Filling Textbox On combobox Selected Index Changed with SQL Database

  23. 23

    Textbox Array connected MySQL database

  24. 24

    Connection to database using XAMPP

  25. 25

    ERROR 1045: Transferring SQL database from one server to another

  26. 26

    How to create SQL Server 2012 database with C#?

  27. 27

    how can we change the date format of SQL Server(2008) Database?

  28. 28

    How can I change properties of FK in SQL Server database project?

  29. 29

    Drop all objects in SQL Server database that belong to different schemas?

뜨겁다태그

보관