Hi , Im new to asp.net and im need help connecting to an sql server databse in vb.net. I tried so many things and its still not working. I also need hep with inseting, updating and deleting data from a webform into the sql server database.

Dani AI

Generated

asked about connecting ASP.NET (VB.NET) to SQL Server and doing insert/update/delete from a web form. pointed to an Access/OleDb article; that is useful for concepts but not the right provider for SQL Server. For SQL Server use ADO.NET's SqlClient (System.Data.SqlClient), keep the connection string in web.config and retrieve it with ConfigurationManager, and always run parameterized commands inside Using blocks so connections are closed reliably. As offered to help, the most useful diagnostics are the exact connection string, the exception text, and a minimal code snippet.

Minimal safe pattern (VB.NET):

Dim cs As String = ConfigurationManager.ConnectionStrings("MyConn").ConnectionString
Using conn As New SqlConnection(cs)
    conn.Open()
    Using cmd As New SqlCommand("INSERT INTO Persons (FirstName, LastName) VALUES (@FirstName, @LastName)", conn)
        cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = firstName
        cmd.Parameters.Add("@LastName", SqlDbType.NVarChar, 50).Value = lastName
        cmd.ExecuteNonQuery()
    End Using
End Using

Quick checklist and tips:

  • Confirm server/instance name (example: .\SQLEXPRESS or ServerName\Instance) and port.
  • Enable TCP/IP and SQL Server Browser for named instances; check firewall rules.
  • Choose auth mode correctly: Integrated Security=True for Windows auth or User Id=...;Password=...; for SQL auth (enable mixed mode on server if needed).
  • Test connectivity with SQL Server Management Studio or sqlcmd to separate network/auth issues from code.
  • Always use parameterized commands (avoid SQL injection) and prefer explicit parameter types over AddWithValue for predictable behavior.

For API details see the SqlConnection reference and guidance on enabling server network protocols: SqlConnection (System.Data.SqlClient) and Enable or disable a server network protocol.

Recommended Answers

All 2 Replies

hi,
Read this article which used Connection to Access from ASP, I can also write using SQL.
Click Here to read the full article

You can also download a sample app. from this page.

just send the code whatever written by u-i will check it out& give the suggestion....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.