connection problem

  • hi !!

    I am trying to connect to Sql Server using VB .Net,

    1 >

    Dim SqlConn As New System.Data.SqlClient.SqlConnection

            SqlConn.ConnectionString

    ="server=localhot;uid=sa;pwd=;database=Northwind" 

    SqlConn.Open()

    I am getting an error

    "Login failed for user 'sa'. Reason: Not associated

    with a trusted SQL Server connection"

    2>

    Dim

    SqlConn As New ADODB.Connection

    Dim str1 As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=RISDatabase;Data Source=SHITAL-20"

    SqlConn.Open(str1)

     I am getting an error

    Login failed for user 'SHITAL-20\ASPNET'

    Pl. Help me out

    Shital

  • For #1 I would ensure that the security of your server is set in mixed mode and not windows mode only. SQL security tab under properties when you right-click on your server.

     



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • thanks AJ Ahrens !!

  • "server=localhot;uid=sa;pwd=;database=Northwind" 

    I guess you want to connect local.

    Try server=.

    or server=localhoSt

    btw : even on dev/test server it is not wize to have sa-password blank or use sa in connections with apps 

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Hi Shital, Try this

    "data source=localhost; initial catalog=NorthWind;uid=sa;pwd=<your sa password>" />

     

    Another way is this

    in yuor app web.config

    <add key="UsrConnectionString" value="data source=localhos; initial catalog=Northwind;uid=sa;pwd=sa" />

    and your webform

    Dim oSqlConnect As New SqlConnection(ConfigurationSettings.AppSettings("UsrConnectionString"))

    oSqlConnect .Open()

  • Since you are using integrated security, consider using a udl file.  Avoid hard coded connection strings whenever possible.

    http://support.microsoft.com/kb/244659/EN-US/

    http://support.microsoft.com/default.aspx?scid=kb;en-us;274536

    Dim db As New adoDb.Connection 
    db.Open gUDL
    Function gUDL() As String
        Call FormatPath(gUDL, CurrentProject.Path)
        gUDL = "FILE NAME=" & gUDL & Left(CurrentProject.Name, Len(CurrentProject.Name) - 3) & "UDL"
    End Function
    Function FormatPath(pDir, pDefault) As Boolean
        On Error GoTo ErrorHandler
        If pDir = "" Then
            pDir = pDefault
        End If
        If Right(Trim(pDir), 1) <> "\" Then
            pDir = Trim(pDir) & "\"
        End If
    NormalExit:
        On Error Resume Next
        Exit Function
    ErrorHandler:
        MsgBox Err.DESCRIPTION, vbCritical, "Error Occurred"
        Resume NormalExit
    End Function

     

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply