CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Angry Sql Database Connection

    whats wrong with my codes, i cant connect to my database...pls help!
    ERROR CONNECTING TO DATABASE

    Imports System.Data.SqlClient
    Imports System.Data

    Public Class LoginForm1

    ' TODO: Insert code to perform custom authentication using the provided username and password
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).
    ' The custom principal can then be attached to the current thread's principal as follows:
    ' My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication.
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click

    Dim conn As SqlConnection
    conn = New SqlConnection()
    conn.ConnectionString = "Data Source=JING2; Initial Catalog=AFJIS"

    Try
    conn.Open()
    Catch myerror As SqlException
    MsgBox("Error Connecting to Database")

    End Try

    Dim MyAdapter As New SqlDataAdapter

    Dim Sqlquery = "Select * From syscontrol Where username = '" + txtuser.Text + "' And
    password = '" + txtpass.Text + "'"
    Dim MyCommand As New MySqlCommand()
    MyCommand.Connection.conn()
    MyCommand.Commandtext = Sqlquery

    Dim MyData As SqlDataReader
    MyData = MyCommand.ExecuteReader()

    If MyData.HasRows = 0 Then
    MsgBox("Invalid Login")

    Else
    MsgBox("Login Accepted")
    Me.Hide()

    End If

    Me.Close()

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
    Me.Close()
    End Sub

    End Class

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Sql Database Connection

    Doesn't look like a valid connection string.

    Find what you need here:
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2007
    Posts
    234

    Re: Sql Database Connection

    Yeah... I can tell just by looking at that connection string, it's not valid for SQL Server. OR... conversely, the use of the SQLClient namespace isn't valid for the type of database being connected to.

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

  4. #4
    Join Date
    Oct 2010
    Posts
    3

    Post Re: Sql Database Connection

    In vb.net, I created upload button to upload csv file to MS Access in vb.net. Can you please help me with coding to upload csv file.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Sql Database Connection

    Your question has been answered. Please don't double-post.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured