Solved

mssql db con via web.config

Posted on 2014-10-02
8
93 Views
Last Modified: 2015-04-15
Hi,

I have the following in a web.config file for a db connection:

<connectionStrings>
        <add
          name="AppUsrConnectionString"
          connectionString="Data Source=CSQL03\BAPPS;Initial
          Catalog=AALSMGNT;Persist Security Info=True;User
          ID=AER;Password=Abc765456"
          providerName="System.Data.SqlClient"
        />
    </connectionStrings>

Based on the above settings i am trying to connect to a mssql 2012 database using the following classic asp vb coding:

Dim strConnection
            strConnection = ConfigurationManager.ConnectionStrings("AppUsrConnectionString").ToString()

to execute below query:

Dim strQueryUserCheckCount
strQueryUserCheckCount = "SELECT count(*) FROM AppUsrD where AppUsr_DWI = '" & Session("UserName") & "'"
'--- build connections for query executions
            Dim objStringDataConnectionStrQueryUserCheckCount
            objStringDataConnectionStrQueryUserCheckCount = New SqlConnection(strConnection)
            objStringDataConnectionStrQueryUserCheckCount.Open()

Dim objConnStrQueryUserCheckCount, userRecordCountCheck
            objConnStrQueryUserCheckCount = New SqlCommand(strQueryUserCheckCount, objStringDataConnectionStrQueryUserCheckCount)
            userRecordCountCheck = objConnStrQueryUserCheckCount.ExecuteScalar()

However i am not able to connect to database. please some help in making it work and in creating a db connection test page.

Thanks in advance
0
Comment
Question by:eaweb
  • 4
  • 2
8 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40358198
You should only need something like

strConnection = "Provider=SQLOLEDB; Server=localhost; database=db_name; uid=user_name; Password=pass_word;"


http://www.connectionstrings.com/sql-server-2012/
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40358207
also, this looks to be .NET, should probably be moved to that area for better responses
0
 

Author Comment

by:eaweb
ID: 40358248
No, changing the connection still doesn't work.

Can you help me with a connection test page maybe?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:eaweb
ID: 40358266
Hi admin
Please move my question to the .Net area,
0
 

Author Comment

by:eaweb
ID: 40366779
use asp.net vb
0
 

Author Comment

by:eaweb
ID: 40581637
Hi,

Please some help.
Thanks!
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 40581653
it looks like you're using classic asp code, which is entirely different from asp .net. when you do

Dim strQueryUserCheckCount

that's syntax for classic asp, if it was .NET you would have to declare the data type, like this:

Dim strQueryUserCheckCount as String

what's the extension on the web page you're using, fileName.ASP or fileName.ASPX?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question