locked
DSN Connection RRS feed

  • Question

  • I want to connect with sqlserver database using dsn connection.  I want to connect using "Integrated Security=SSPI" How can I achieve this using ADODB.Connection .


    Thanking you in advance

    Waiting for your valuable thoughts. 
    Monday, December 15, 2008 10:10 AM

Answers

  •  Hi Furqams
    please look this link:


    Connecting to a SQL Server Data Source
    http://msdn.microsoft.com/en-us/library/aa905872(SQL.80).aspx



    ' Initialize variables.  
    Dim cn As New ADODB.Connection  
    . . .  
    Dim ServerName As String, DatabaseName As String  
     
    ' Put text box values into connection variables.  
    ServerName = txtServerName.Text  
    DatabaseName = txtDatabaseName.Text  
     
    ' Specify the OLE DB provider.  
    cn.Provider = "sqloledb" 
     
    ' Set SQLOLEDB connection properties.  
    cn.Properties("Data Source").Value = ServerName 
    cn.Properties("Initial Catalog").Value = DatabaseName 
     
    ' Windows NT authentication.  
    cn.Properties("Integrated Security").Value = "SSPI" 
     
    ' Open the database.  
    cn.Open  
    B. Using  

    Using SQL Server 2005 Express from Visual Basic 6

    http://msdn.microsoft.com/en-us/library/bb264566(SQL.90).aspx


    If you have any issue, please feel free to tell me.

    Best wish
    Xingwei Hu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Xingwei Hu Friday, December 19, 2008 10:29 AM
    Friday, December 19, 2008 10:27 AM
  • hi furqanms,

    youcould  look this website about connection string.
     
    http://www.connectionstrings.com/

    Please try this .

    Provider
    =sqloledb;Data Source=myServerName\theInstanceName;Initial Catalog=myDataBase;Integrated Security=SSPI;

    Best Wishes
    Xingwei Hu

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Furqanms Thursday, December 25, 2008 6:20 AM
    Thursday, December 25, 2008 3:06 AM

All replies

  •  Hi Furqams
    please look this link:


    Connecting to a SQL Server Data Source
    http://msdn.microsoft.com/en-us/library/aa905872(SQL.80).aspx



    ' Initialize variables.  
    Dim cn As New ADODB.Connection  
    . . .  
    Dim ServerName As String, DatabaseName As String  
     
    ' Put text box values into connection variables.  
    ServerName = txtServerName.Text  
    DatabaseName = txtDatabaseName.Text  
     
    ' Specify the OLE DB provider.  
    cn.Provider = "sqloledb" 
     
    ' Set SQLOLEDB connection properties.  
    cn.Properties("Data Source").Value = ServerName 
    cn.Properties("Initial Catalog").Value = DatabaseName 
     
    ' Windows NT authentication.  
    cn.Properties("Integrated Security").Value = "SSPI" 
     
    ' Open the database.  
    cn.Open  
    B. Using  

    Using SQL Server 2005 Express from Visual Basic 6

    http://msdn.microsoft.com/en-us/library/bb264566(SQL.90).aspx


    If you have any issue, please feel free to tell me.

    Best wish
    Xingwei Hu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Xingwei Hu Friday, December 19, 2008 10:29 AM
    Friday, December 19, 2008 10:27 AM
  • Thanks for your reply


    I have created System DSN and I need to connect database without UserName and password. I want to use Integrated Security=SSPI


    My System DSN Name is XYZ

    if True then 
                Con.Open("dsn=xyz") // Here I need to connect with Integrated Security 
    else 
                Con.Open("dsn=xyz;uid=sa;pwd=abc") 
     
    end if 

    I am using sql server 2000.


    Thanking  you in advanced.


    Wednesday, December 24, 2008 11:12 AM
  • hi furqanms,

    youcould  look this website about connection string.
     
    http://www.connectionstrings.com/

    Please try this .

    Provider
    =sqloledb;Data Source=myServerName\theInstanceName;Initial Catalog=myDataBase;Integrated Security=SSPI;

    Best Wishes
    Xingwei Hu

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Furqanms Thursday, December 25, 2008 6:20 AM
    Thursday, December 25, 2008 3:06 AM