Hello
I wonder if you can help me. I am learning asp.net and am wanting to find out how to connect to a database on jodohost and instert data into a table (with MSSQL).
Does anyone have any sample code I could look at?
Thanks
Steve
Hello
I wonder if you can help me. I am learning asp.net and am wanting to find out how to connect to a database on jodohost and instert data into a table (with MSSQL).
Does anyone have any sample code I could look at?
Thanks
Steve
Well, no one has replied so I’ll give you a little help. I created a function in my ASP.NET page to connect to a database and I just call it when I need it. There is one parameter that I pass, which is a structure I created to hold all of the input parameters for the connection string.
Basically to call this function declare yourself a boolean variable and assign it to this function call. For example:
Dim blnConnectStatus As Boolean
'// Attempt connection to database
blnConnectStatus = Connect(structConn)
If blnConnectStatus = False Then
Response.Write("Connection Failed!")
Else
Response.Write("Connection Succeeded!")
End If
Now here’s the function that does the connection work to SQL Server:
Private Function Connect(ByRef structConn As ConnectionOptions) As Boolean
On Error GoTo Connect_Err
Dim strConn As String
'// Attempt to open the config.xml file & pass the database config info into connect string
structConn.cnn = New SqlClient.SqlConnection
strConn = "integrated security=SSPI;" & _
"server=" & structConn.strServer & ";" & _
"persist security info=False;" & _
"initial catalog=" & structConn.strInitialCatalog & ";" & _
"Trusted_Connection=" & structConn.strTrustedConnection & ";" & _
"User ID=" & structConn.strUserID & ";" & _
"Password=" & structConn.strPassword
structConn.cnn.ConnectionString = strConn
'// Attempt to open the connection
structConn.cnn.Open()
Connect = True
Exit Function
Connect_Err:
Connect = False
End Function
Now I have only created tables in my code; I haven’t written any code to write to those tables yet. Why don’t you try what I’ve supplied you and let me know how it goes.
Thanks..
Michael