dsn question

Results 1 to 3 of 3

Thread: dsn question

  1. #1
    Join Date
    Dec 1969

    Default dsn question

    i am trying connect to a dsn thru my asp.net pages and am having trouble, so i need to ask which would be the best connection to use.<BR><BR>right now, i&#039;m using OleDb but can only do c:....mdb datasource<BR>SqlClient (according my instruction) works w/ Sql Server<BR>my host provider doesn&#039;t recomm. Odbc<BR><BR>Could someone recommend the correct one to use for a DSN and a simple example. thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: dsn question

    I&#039;m not sure I understand what you WANT to do. A DSN is always going to use ODBC. So it sounds like you want to use a DSN-less connection string.<BR><BR>If you are connecting to an Access DB you can do it using the MS Jet data provider with a connection string like this:<BR><BR>"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:inLocalAccess40.mdb;"<BR><BR>See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbConnectionClassConnection StringTopic.asp<BR><BR>Or: http://msdn.microsoft.com/library/en-us/oledb/htm/oledbconnectionstringsyntax.asp<BR><BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Here's an example that may help...

    I don&#039;t know that I understand either. See it this helps...use this bare bones web.config file. Putting it in web.config lets you reuse it throughout the directory and/or site. Put your OleDb connection there (note mine is SQL Server but easy to change).<BR><BR>&#060;configuration&#062;<BR>&#060 ;appSettings&#062; <BR>&#060;add key="myConn" value="Data Source=mySQLServer;Initial Catalog=myDatabase;Min Pool Size=10;Max Pool Size=255;user id=myUser;pwd=myPassword;" /&#062; <BR>&#060;/appSettings&#062;<BR>&#060;/configuration&#062;<BR><BR>Then in your page do something like this...<BR><BR>Sub mySignInButton_Click(obj As Object, e As EventArgs)<BR>Dim strmyCconn As SqlConnection<BR>strMyConn = New SqlConnection(ConfigurationSettings.AppSettings("m yConn"))<BR>Dim mySqlCommand As New SqlCommand("myStoredProceedure",strMyConn)<BR>mySq lCommand.CommandType = CommandType.StoredProcedure<BR><BR>&#039;Open connection<BR>Try<BR>strMyConn.Open()<BR>&#039; NOTE: "ExecuteNonQuery" only returns OUTPUTS...no records!<BR>mySqlCommand.ExecuteNonQuery()<BR>strM yConn.Close()<BR>Catch ex As SQLException<BR>lblWelcomeMessage.Text = "Catch Error = " & ex.Message<BR>End Try<BR>mySqlCommand = Nothing <BR>strMyConn = Nothing<BR>End Sub<BR><BR>You&#039;ll need to change "SQL" to "OleDb" to make this work for Access. Also you still need to specify parameters and such. This is only a template...not responsible for fat fingers :)

Posting Permissions

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