Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Saturday, February 25, 2012

access Sql from asp.net

hi,

i have few forms in my form.i dont want to repeat coding for database connectivity.i want to make it as standard in one file.so that in future if any changes in database i can access that file and modify it.

im using global.aspx file here

Sub Session_Start(ByVal senderAsObject,ByVal eAs EventArgs)

' Fires when the session is started

Session("ConnectionPath") ="DRIVER={SQL server};SERVER=localhost;UID=sa;PWD=;DATABASE=mas;"

EndSub

now in my forms how can i access this connection path without repeatin the above code again in my dim con = new sql(...) i dont want to do like this..

You need to use the web.config...

add this

<?xmlversion="1.0"?>
<configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<addname="ConnectionString"connectionString="Data Source=<SERVERNAME>;Initial Catalog=<DATABASENAME>;UID=<USERNAME>;Password=<PASSWORD>;"providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
......
</system.web>
</configuration>

Then in you code behind do this to access is...

Dim conn as SqlConnection =New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)


|||

Or better you create a public shared method and create it there.

|||

Error 101 Value of type 'System.Configuration.ConnectionStringSettingsCollection' cannot be converted to 'String'.

im getting this error

|||

Since you have added the connection string in session variable, use the below code to access it Dim conn as SqlConnection = New SqlConnection(session("ConnectionPath"))

|||

hi, thankyou,i manged to solve it with all ur advices...

i have a doubt in procedure.is it possible to retive value of a column from a table inside procedure?someth like this

cREATE PROCEDURE a @.val varchar(50)
AS
declare @.type char(2)
set @.type='select id from dbo.Handle_Master where name = @.val'
if @.type='A'
Begin .....

if @.Type='B'

Begin...

someth like this...is that possible??if can!! how ?i tried like this but no error and no result also...

|||

wat i felt here is instead of accesing from table ,i planned to pass the value as parameter...jus changed the logic...its workin fine...

Access SQL Conversion Issues?

Hi there, apologies if i have entered this into the wrong forum.

I am currently building an application using microsoft access and coding in VBA (what i can!)

When i have got it working as i like after user testing i would like to create an MDE file to distribute to users and i would like to convert the access database held on a file server to a SQL server but have no experience of doing this.

In what order would i do this and would i suffer a loss of functionality in changing from access to SQL i.e. would some of the VBA code not work in SQL?

Thanks for your time,

Rhys.

Yes, you are right, if you do not use the GUI "only", you *could* get into problems after migrating. If you already know that you will switch to the SQL Server option, you should build your application directly on top of that.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de|||

Hello

Have you tried importing the Access database using SQL Server Integration Services (or Data Transformation Services if you use SQL Server 2000)?
I'm not sure if it works with MDE files but I would give it try.

Let us know if it works

Worf

|||

one thing you have to watch out are the stored procedure.

in access it looks like this

select * from employees where employee_id=?

while in SQL server it looks like this

Select * from employees where employee_id=@.employeeid