Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Wednesday, March 28, 2012

how to connect with sqlexpress2005 & asp.net for update insert delete codings

I want to know about the how to connect with asp.net 2005 and sqlexpress through codings using parameters

import System.Data.SqlClient;

related update delete insert codings ...

How to know about the make the new connection with different databases sqlserver, oracle mysql...

Hi

Have you had a lookhttp://quickstarts.asp.net/QuickStartv20/default.aspx andhttp://www.asp.net/learn/data-access/.

Work through these samples.. They explain how to access databases using declarative coding (sqldatasource and the likes) and coe behind coding.

Hope that helps.

VJ

How to connect with SQL database?

I am new learner of ASP.NET and coding in C#.I am not able to connect the SQL database.I have written the code for connection of database but to write the connection string web.config file is neccessary which is not apearing in my application. Please help me .Here is code I have written.

string sCon =ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

SqlConnection oCon =new SqlConnection(sCon);

try

{

oCon.Open();

string sQuery ="Select Offering1,Offering2,Offering3 from Offering";SqlCommand oCmd =new SqlCommand(sQuery, oCon);

oCmd.ExecuteNonQuery();

DataSet oDs =newDataSet();

SqlDataAdapter oDa =new SqlDataAdapter(oCmd);

oDa.Fill(oDs);

DataList1.DataSource = oDs;

DataList1.DataBind();

}

catch (Exception ex)

{

ex.ToString();

}

What kind of error are you getting?

Can you post a copy of the connectionString settings from your web.config?

|||

Hii Jimmy,

Actually I do not see the web.config file in my solution explorer. So that I am unable to write the connection string. Can you please tell me why it is so ?

|||

Looks like you may have started with the empty web site template. When you try to start/debug the application, does it not automatically add a web.config for you?

Well, you can manually add one. Right click on your web site and select ADD NEW ITEM then select the WEB CONFIGURATION FILE

|||

Hey thanks,

As there are errors because I have not added the connection string into the web.cofig file it is not able to debug the file.Right now I have added web.config manually.

What the connection string format to add to web.config?

<addname="ConnectionString"connectionString="Server=(local)\SQLEXPRESS;Integrated Security=True;Database=Knowledgebase;Persist Security Info=True"/>

is it right?

Now the error coming is "The type or namespace name 'SqlConnection' could not be found" when I try to debug my default.aspx.

|||

Bluestar123:

Now the error coming is "The type or namespace name 'SqlConnection' could not be found" when I try to debug my default.aspx.

That would because you did not import the namespace

Add this to the top of your code behind for your default.aspx

using System.Data.SqlClient;

|||

The connection string can look something like this

"Data Source= xxx ;Initial Catalog=xxx; uid=xxx ;pwd=xxx"

where datasource is your database server; could be your machine name or I.P. address, Initial Catalog is the database name, UID is the login name, PWD is the login name's password

If your SQL Server is set up for windows authentication then you can do replace the UID and PWS with "Integrated Security=True"

Have a look at this link for connection string examples

http://connectionstrings.com/?carrier=sqlserver2005

|||

Hi Jimmy,

Now I have added using System.Data.SqlClient to my default.aspx.cs and that error has gone thanks for the same.

I am still not able to fetch the data to my datalist from database, is still there any problem with my connection string? in my web.cofig I have used windows authentication.

<addname="ConnectionString"connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Knowledgebase;Integrated Security=True"/>

Please help ..........

|||

Bluestar123:

<addname="ConnectionString"connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Knowledgebase;Integrated Security=True"/>

for the connection string, the data source should be [your machine name]\SQLEXPRESS assuming SQLEXPRESS is the server instance name

update your code to this and give it a go

string sCon = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection oCon =new SqlConnection(sCon);

try
{
string sQuery ="Select Offering1,Offering2,Offering3 from Offering";
SqlCommand oCmd =new SqlCommand(sQuery, oCon);

DataSet oDs =new DataSet();
SqlDataAdapter oDa =new SqlDataAdapter(oCmd);

oDa.Fill(oDs);
DataList1.DataSource = oDs;
DataList1.DataBind();
}
catch (Exception ex)
{
ex.ToString();
}

Add some break points and step through the code, if there any exceptions, take not of the exception message.

|||

I have added break points at Select command and line below that ,control goes there when I debug the default.aspx and then it display the page without fetching thedata from database.So i have added the break point to the line

DataSet oDs=new DataSet();

at this line control donot go and directly display the page without showing the data from the database.

|||

So when you put a break point at the DataSet oDs=new DataSet(); and when you step over it F10, it does not proceed to the next line? Then that means an exception was raised and it should be caught in your catch. So put a break point in your catch statement, so you can check the exception being thrown if there is one at all and give us the error message

|||oops! Column name I had given was wrong .......Its OfferingName. I made that change but now when I put brk point at

DataList1.DataSource = oDs;

after pressing F10 control goes to next line i. e.

DataList1.DataBind();

but data from database is not getting displayed on the page though the page has been displayed......

oh no whats the problem ?am I doing any mistake again?

Follwing output I got in Output window

Warning: Cannot debug script code. Script debugging is disabled for the application you are debugging. Please uncheck the 'Disable script debugging' option on the Internet Options dialog box (Advanced page) for Internet Explorer and restart the process.

'WebDev.WebServer.EXE' (Managed): Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\knowledgebase\23a636d8\418c589d\App_Web_d4ehzmko.dll', No symbols loaded.

'WebDev.WebServer.EXE' (Managed): Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\knowledgebase\23a636d8\418c589d\App_Web_oq4mi2vf.dll', Symbols loaded.

The program '[3368] WebDev.WebServer.EXE: Managed' has exited with code 0 (0x0).

|||

Well the obviously question is have you tried executing the SQL statement against your database to make sure it does return data?

after you have stepped over this line of code oDa.Fill(oDs); check it the dataset has returned a datatable with datarows.

|||

No I didnt,how can I check it ?I am using Microsoft SQL server management Studio. When go to line

oDa.Fill(oDs);

it did not return the table contents......

I tried to execute the query by using Execute SQL but not able to execute ,How to do?

Did you get fed up of my questions Jimmy??

|||

Bluestar123:

Did you get fed up of my questions Jimmy??

Not at all, just trying my best to understand your problem which is at times a little hard.

Lets try execute you select statement first in SQL Server Management Studio.

Log onto your database, and select the NEW QUERY option.

Now paste your SQL statement into this window , "Select Offering1,Offering2,Offering3 from Offering" and click execute

Does it return any results?

sql

How to connect using C#

Hi

I'm trying to connect to a MS SQL Server using ASP.NET / C#. I've
already got some VB code that works but I'm unable to translate it to
working C# code. Can anyone help me out?

Working VB code:

Dim Conn
Conn = CreateObject("ADODB.Connection")
Const ConnectionString = "DSN=dsn_name;database=database_name"
Conn.Open(ConnectionString, "user_name", "password")

Not working C# code:

string ConnectionString = "Initial Catalog=database_name;" +
"Data Source=dsn_name;" +
"User ID=user_name;" +
"Password=password;" +
"Integrated Security=SSPI;";

SqlConnection Connection = new SqlConnection(ConnectionString);
Connection.Open();
Connection.Close();Use exactly the same connection string form C# as for VB. If it works
in one, it'll work in the other.

Specifically, if you are using SSPI, you don't need to specify uid and
pw, and vice-versa.|||AHM (ingen@.spam.tak) writes:
> I'm trying to connect to a MS SQL Server using ASP.NET / C#. I've
> already got some VB code that works but I'm unable to translate it to
> working C# code. Can anyone help me out?

If you help us to help you. Don't just post:

> Not working C# code:
> string ConnectionString = "Initial Catalog=database_name;" +
> "Data Source=dsn_name;" +
> "User ID=user_name;" +
> "Password=password;" +
> "Integrated Security=SSPI;";
> SqlConnection Connection = new SqlConnection(ConnectionString);
> Connection.Open();
> Connection.Close();

Tell us in what way it is not working. Do you get an error message?
Do you get unexpected results? Does the light go out?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||> string ConnectionString = "Initial Catalog=database_name;" +
> "Data Source=dsn_name;" +
> "User ID=user_name;" +
> "Password=password;" +
> "Integrated Security=SSPI;";

Note the change to 'Data Source' in the example below as well as the removal
of the unnecessary User ID and Password parameters:

string ConnectionString = "Initial Catalog=database_name;" +
"Data Source=database_server_name;" +
"Integrated Security=SSPI;";

--
Hope this helps.

Dan Guzman
SQL Server MVP

"AHM" <ingen@.spam.tak> wrote in message
news:MPG.1cb65eb0b33ffb61989705@.news.inet.tele.dk. ..
> Hi
> I'm trying to connect to a MS SQL Server using ASP.NET / C#. I've
> already got some VB code that works but I'm unable to translate it to
> working C# code. Can anyone help me out?
> Working VB code:
> Dim Conn
> Conn = CreateObject("ADODB.Connection")
> Const ConnectionString = "DSN=dsn_name;database=database_name"
> Conn.Open(ConnectionString, "user_name", "password")
> Not working C# code:
> string ConnectionString = "Initial Catalog=database_name;" +
> "Data Source=dsn_name;" +
> "User ID=user_name;" +
> "Password=password;" +
> "Integrated Security=SSPI;";
> SqlConnection Connection = new SqlConnection(ConnectionString);
> Connection.Open();
> Connection.Close();

How to connect to sql server on another machine through asp.net

Hi All,

I have been struggling with this problem for quite some time. Basically
i have an asp page (on the ISP server) that I want to connect to a sql
server on another machine (on my server) and I have been trying to
figure out how to do this. I tried to connect using an ip address in
the data source and it did not work. The asp.net code looks something
like this:

Conn.Open ("Provider=SQLOLEDB;Password=xxxx;Persist Security
Info=True;User ID=xxxx;Initial Catalog=mssqlxxx;Data
Source=xx.xxx.xxx.xxx,1433;Network Library=dbmssocn")

That did not work. Gave me an access denied or sql server does not
exist error. I tried playing around with or without the 1433 port,
still no luck.

Is there something I need to set up on sql server in order for me to
connect to this?? Can someone give me some suggestion how i can connect
to another computer?

My ISP offers sql server support and they give me an ip address to
connect directly to the sql server, code looks something like this:

conMyData = New SqlConnection( "Server=xxxxxxxxx.registeredsite.com;
UID=userxxxxxx; PWD=xxxxxx;Database=samplecom" )

now, my question is, how do I set up my sql server to have an ip
address so i can connect??

so i see 2 possible w ays to do this but i have no clue to make this
work. Any help is appreciated.This article might be useful:

http://www.aspfaq.com/show.asp?id=2126

Simon

Monday, March 26, 2012

How to connect to SQL Database, Create tables

Hi All, 1st of all happy New Year to all asp.net forum members
I am new at asp.net. I want to design a websiteusing asp.net as frontend and sql database as backend. I am able toconnect and add,update as well delete records when I use MsAcess andAsp.net using the following connection strings...
**********
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/database/northwind.mdb"))
dbconn.Open()
sql="SELECT * FROM customers where city LIKE 'Berlin' order by city ASC"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
customers.DataSource=dbread
customers.DataBind()
dbread.Close()
dbconn.Close()
end sub
**********

But when I try to connect to sql database using the following connection strings I am unable to do so...

**************
SqlConnection myConnection = new SqlConnection("server=PLATINUM\VSdotNET;database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter(" * from Authors", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");

MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();

**************
I have written the servername as "PLATINUM\VSdotNET" because when Iinstalled SQL SERVER 2000 I found a tray icon where the server name wasdisplaying the same (my computer name is PLATINUM).
When I used webmatrix I enterd the same server name and windowsauthentication I was able to create a database but How to createtable...

Please help me out
Thanks in advance...Please explain "I am unable to do so". Are you receiving an error message?|||Actually I don't know whether the connection string I am using is correct or not...
Because I am unable to create tables using the connection strigns what I told before...

when I try running this page I get the error message like
Compiler Error Message:CS1009: Unrecognized escape sequence
and the compiler shows a error in the connection string , So as far I guess there is problem with the connection string only.

If I get a sample page for what I am trying to do i.e connecting to SQLdatabase, Creating tables as well as accessing table my problem will besolved.
Thanks for your time.


|||Well, I always use this resource for building connection strings:http://www.connectionstrings.com/ Check out the SqlConnection (.NET) options under SQL Server. Yourproblem *might* be that you should use True, not Yes, forTrusted_Connection. In any case, I would try to stick as closelyas possible to the advice listed there.|||* from Authors is not a valid SQL Statement. Try SELECT * FROM Authors

How to connect to Remote SQL Server database using SQL Server 2005 Express

Hi,

I've an account with a hosting service provider online for SQL Server database. I've downloaded SQL Server 2005 Express from ASP.Net. How can I use it to connect to my SQL Server Database which is sitting on remote server? The hosting provider gave me following things to connect to the remote database.

Server Name
Database Name
User Name
Password

Regards,
A.K.R

Anyone?

|||I don't want to ask the obvious, but is there not a Read Me fileincluded with the download of SQL Express which would explain how toconnect?

Sorry I can't be more helpful, but I've only ever briefly looked at SQLExpress and decided to stick to MSDE since I could not see any benefitof using Express when MSDE is a cheap but far more powerful option thanSQL Express.

how to connect to MDF file with classic ASP?

You might want to have a look at some of these:
http://msdn2.microsoft.com/en-us/library/ms345154.aspx Express Overview
http://msdn2.microsoft.com/en-us/library/ms165672.aspx Comparing Express
with MSDE
http://msdn.microsoft.com/sql/default.aspx?pull=/library/en-us/dnsse/html/sqlexpuserinst.asp
User Instances
http://www.datamasker.com/SSE2005_NetworkCfg.htm Configuring Express
for Remote Access
https://blogs.msdn.com/sqlexpress/archive/2005/05/05/415084.aspx
Configuring Remote Access
http://www.kbalertz.com/Feedback_914277.aspx Configuring SQL2005 for
remote access
http://msdn.microsoft.com/sql/express/default.aspx?pull=/library/en-us/dnsse/html/emsqlexcustapp.asp
Embedding Express in Apps
http://www.microsoft.com/downloads/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&DisplayLang=en
SSMS Express
http://blogs.msdn.com/rogerwolterblog/archive/2006/04/13/575974.aspx
Backing up Express
Andrew J. Kelly SQL MVP
"Bart" <b@.sdq.dc> wrote in message
news:%23%23w0O9RbHHA.3584@.TK2MSFTNGP02.phx.gbl...
> Hi,
> i have already posted this problem in an ASP newsgroup without succes, so
> i try here.
> I try to access within an cliassic ASP page an MDF file (newres.mdf) of
> sql server express 2005 database which is located in
> c:\inetpub\wwwroot\reskrosql\App_Data.
> I get following error :
> Provider error '80040e21'
> Multiple-step OLE DB operation generated errors. Check each OLE DB
> status value, if available. No work was done"
> The code in ASP file:
> --
> <%
> set objdc = Server.CreateObject("ADODB.Connection")
> objdc.Open(application("newres")) 'error line
> %>
> global.asa:
> --
> Sub Application_OnStart
> Application("newres") =
> "Provider=SQLOLEDB;DATABASE=c:\inetpub\wwwroot\res krosql\App_Data\newres.mdf;Data
> Source=.\SQLEXPRESS;AttachDbFilename=c:\inetpub\ww wroot\reskrosql\App_Data\newres.mdf;Integrated
> Security=True;User Instance=True"
>
> 'i also tried this:
> Sub Application_OnStart
> Application("newres") = "Provider=SQLOLEDB;DATABASE=newres;Data
> Source=.\SQLEXPRESS;AttachDbFilename=c:\inetpub\ww wroot\reskrosql\App_Data\newres.mdf;Integrated
> Security=True;User Instance=True"
> End Sub
> Thanks for help
> Bart
>
>
Well to be honest I am not sure if classic ASP can access SQL Express or
not. I don't mess with express much but the first link did say there was
some issues with earlier versions of MDAC and connecting under certain
conditions. Look here under Data Access section:
http://msdn2.microsoft.com/en-us/library/ms345154.aspx
In the below link it goes into great detail about connecting using
AttachDBFileName but not necessarily with classic ASP.
http://msdn2.microsoft.com/en-us/library/bb264564.aspx
Have you tried this with .net and or the SNAC driver to see if you can get
it to work at all yet?
Andrew J. Kelly SQL MVP
"Bart" <b@.sdq.dc> wrote in message
news:epUZNiXbHHA.260@.TK2MSFTNGP02.phx.gbl...
> Thanks Andrew,
> to be honest, i read all of them but could not find an example of a
> connectionstring for ASP using AttachDbFilename
> and i'm getting fed up to read and search for 2 days something that is not
> even so particular. I get the impression that it's the first time someone
> try this ...
> What i noticed is that when i change the connectionstring with a false
> path, like:
> "Provider=SQLOLEDB;Data
> Source=.\SQLEXPRESS;AttachDbFilename=c:\WRONGPATH; Integrated
> Security=True;User Instance=True"
> i still get the same error. Maybe the problem is elsewhere
>
>
|||AttachDBFilename should work from OLEDB or ODBC but the User instance clause
is only available from SQLClient - ADO.Net so it's not clear how much good
AttachDBFilename will do you.
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Bart" <b@.sdq.dc> wrote in message
news:epUZNiXbHHA.260@.TK2MSFTNGP02.phx.gbl...
> Thanks Andrew,
> to be honest, i read all of them but could not find an example of a
> connectionstring for ASP using AttachDbFilename
> and i'm getting fed up to read and search for 2 days something that is not
> even so particular. I get the impression that it's the first time someone
> try this ...
> What i noticed is that when i change the connectionstring with a false
> path, like:
> "Provider=SQLOLEDB;Data
> Source=.\SQLEXPRESS;AttachDbFilename=c:\WRONGPATH; Integrated
> Security=True;User Instance=True"
> i still get the same error. Maybe the problem is elsewhere
>
>
|||Depends on how you define impossible. You can't access it using the
connection string you are trying to use because only ADO.Net understands the
Userinstance parameter. You can definitely attach it to SQL Express and
access it the way you would any other database. You can also access it
through the named pipe name but that's not something I would recommend for a
production system. More information on user instances is available here:
http://msdn2.microsoft.com/en-us/library/bb264564.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Bart" <b@.sdq.dc> wrote in message
news:%23kiVRyZbHHA.4832@.TK2MSFTNGP02.phx.gbl...
> Thanks, so the conclusion is:
> it's impossible to access a MDF file with classic asp?
> "Roger Wolter[MSFT]" <rwolter@.online.microsoft.com> schreef in bericht
> news:EF1406A3-C657-44F9-8FF6-3F1D032175E1@.microsoft.com...
>
sql

how to connect to MDF file with classic ASP?

Hi,
i have already posted this problem in an ASP newsgroup without succes, so i
try here.
I try to access within an cliassic ASP page an MDF file (newres.mdf) of sql
server express 2005 database which is located in
c:\inetpub\wwwroot\reskrosql\App_Data.
I get following error :
Provider error '80040e21'
Multiple-step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done"
The code in ASP file:
--
<%
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open(application("newres")) 'error line
%>
global.asa:
--
Sub Application_OnStart
Application("newres") =
" Provider=SQLOLEDB;DATABASE=c:\inetpub\ww
wroot\reskrosql\App_Data\newres.mdf
;Data
Source=. \SQLEXPRESS;AttachDbFilename=c:\inetpub\
wwwroot\reskrosql\App_Data\n
ewres.mdf;Integrated
Security=True;User Instance=True"
'i also tried this:
Sub Application_OnStart
Application("newres") = "Provider=SQLOLEDB;DATABASE=newres;Data
Source=. \SQLEXPRESS;AttachDbFilename=c:\inetpub\
wwwroot\reskrosql\App_Data\n
ewres.mdf;Integrated
Security=True;User Instance=True"
End Sub
Thanks for help
BartYou might want to have a look at some of these:
http://msdn2.microsoft.com/en-us/library/ms345154.aspx Express Overview
http://msdn2.microsoft.com/en-us/library/ms165672.aspx Comparing Express
with MSDE
http://msdn.microsoft.com/sql/defau... />
erinst.asp
User Instances
http://www.datamasker.com/SSE2005_NetworkCfg.htm Configuring Express
for Remote Access
https://blogs.msdn.com/sqlexpress/a.../05/415084.aspx
Configuring Remote Access
http://www.kbalertz.com/Feedback_914277.aspx Configuring SQL2005 for
remote access
http://msdn.microsoft.com/sql/expre...qlexcustapp.asp
Embedding Express in Apps
http://www.microsoft.com/downloads/...&DisplayLang=en
SSMS Express
http://blogs.msdn.com/rogerwolterbl.../13/575974.aspx
Backing up Express
Andrew J. Kelly SQL MVP
"Bart" <b@.sdq.dc> wrote in message
news:%23%23w0O9RbHHA.3584@.TK2MSFTNGP02.phx.gbl...
> Hi,
> i have already posted this problem in an ASP newsgroup without succes, so
> i try here.
> I try to access within an cliassic ASP page an MDF file (newres.mdf) of
> sql server express 2005 database which is located in
> c:\inetpub\wwwroot\reskrosql\App_Data.
> I get following error :
> Provider error '80040e21'
> Multiple-step OLE DB operation generated errors. Check each OLE DB
> status value, if available. No work was done"
> The code in ASP file:
> --
> <%
> set objdc = Server.CreateObject("ADODB.Connection")
> objdc.Open(application("newres")) 'error line
> %>
> global.asa:
> --
> Sub Application_OnStart
> Application("newres") =
> " Provider=SQLOLEDB;DATABASE=c:\inetpub\ww
wroot\reskrosql\App_Data\newres.m
df;Data
> Source=. \SQLEXPRESS;AttachDbFilename=c:\inetpub\
wwwroot\reskrosql\App_Data
\newres.mdf;Integrated
> Security=True;User Instance=True"
>
> 'i also tried this:
> Sub Application_OnStart
> Application("newres") = "Provider=SQLOLEDB;DATABASE=newres;Data
> Source=. \SQLEXPRESS;AttachDbFilename=c:\inetpub\
wwwroot\reskrosql\App_Data
\newres.mdf;Integrated
> Security=True;User Instance=True"
> End Sub
> Thanks for help
> Bart
>
>|||Thanks Andrew,
to be honest, i read all of them but could not find an example of a
connectionstring for ASP using AttachDbFilename
and i'm getting fed up to read and search for 2 days something that is not
even so particular. I get the impression that it's the first time someone
try this ...
What i noticed is that when i change the connectionstring with a false path,
like:
"Provider=SQLOLEDB;Data
Source=. \SQLEXPRESS;AttachDbFilename=c:\WRONGPAT
H;Integrated
Security=True;User Instance=True"
i still get the same error. Maybe the problem is elsewhere|||Well to be honest I am not sure if classic ASP can access SQL Express or
not. I don't mess with express much but the first link did say there was
some issues with earlier versions of MDAC and connecting under certain
conditions. Look here under Data Access section:
http://msdn2.microsoft.com/en-us/library/ms345154.aspx
In the below link it goes into great detail about connecting using
AttachDBFileName but not necessarily with classic ASP.
http://msdn2.microsoft.com/en-us/library/bb264564.aspx
Have you tried this with .net and or the SNAC driver to see if you can get
it to work at all yet?
Andrew J. Kelly SQL MVP
"Bart" <b@.sdq.dc> wrote in message
news:epUZNiXbHHA.260@.TK2MSFTNGP02.phx.gbl...
> Thanks Andrew,
> to be honest, i read all of them but could not find an example of a
> connectionstring for ASP using AttachDbFilename
> and i'm getting fed up to read and search for 2 days something that is not
> even so particular. I get the impression that it's the first time someone
> try this ...
> What i noticed is that when i change the connectionstring with a false
> path, like:
> "Provider=SQLOLEDB;Data
> Source=. \SQLEXPRESS;AttachDbFilename=c:\WRONGPAT
H;Integrated
> Security=True;User Instance=True"
> i still get the same error. Maybe the problem is elsewhere
>
>|||AttachDBFilename should work from OLEDB or ODBC but the User instance clause
is only available from SQLClient - ADO.Net so it's not clear how much good
AttachDBFilename will do you.
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Bart" <b@.sdq.dc> wrote in message
news:epUZNiXbHHA.260@.TK2MSFTNGP02.phx.gbl...
> Thanks Andrew,
> to be honest, i read all of them but could not find an example of a
> connectionstring for ASP using AttachDbFilename
> and i'm getting fed up to read and search for 2 days something that is not
> even so particular. I get the impression that it's the first time someone
> try this ...
> What i noticed is that when i change the connectionstring with a false
> path, like:
> "Provider=SQLOLEDB;Data
> Source=. \SQLEXPRESS;AttachDbFilename=c:\WRONGPAT
H;Integrated
> Security=True;User Instance=True"
> i still get the same error. Maybe the problem is elsewhere
>
>|||Yes it works with asp.net.
Classic ASP works even when connecting a database in sqlexpress (not a mdf).
I use this stringconnection:
Sub Application_OnStart
Application("newresfull") = "Provider=SQLOLEDB;Data
Source=laptop\sqlexpress;Integrated Security=SSPI;Initial Catalog=test"
End Sub
I think it's simply impossible to access a mdf file with asp ...
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> schreef in bericht
news:%23WmHJhYbHHA.4000@.TK2MSFTNGP02.phx.gbl...
> Well to be honest I am not sure if classic ASP can access SQL Express or
> not. I don't mess with express much but the first link did say there was
> some issues with earlier versions of MDAC and connecting under certain
> conditions. Look here under Data Access section:
> http://msdn2.microsoft.com/en-us/library/ms345154.aspx
>
> In the below link it goes into great detail about connecting using
> AttachDBFileName but not necessarily with classic ASP.
> http://msdn2.microsoft.com/en-us/library/bb264564.aspx
> Have you tried this with .net and or the SNAC driver to see if you can get
> it to work at all yet?
> --
> Andrew J. Kelly SQL MVP
> "Bart" <b@.sdq.dc> wrote in message
> news:epUZNiXbHHA.260@.TK2MSFTNGP02.phx.gbl...
>|||Thanks, so the conclusion is:
it's impossible to access a MDF file with classic asp?
"Roger Wolter[MSFT]" <rwolter@.online.microsoft.com> schreef in bericht
news:EF1406A3-C657-44F9-8FF6-3F1D032175E1@.microsoft.com...
> AttachDBFilename should work from OLEDB or ODBC but the User instance
> clause is only available from SQLClient - ADO.Net so it's not clear how
> much good AttachDBFilename will do you.
> --
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> "Bart" <b@.sdq.dc> wrote in message
> news:epUZNiXbHHA.260@.TK2MSFTNGP02.phx.gbl...
>|||Depends on how you define impossible. You can't access it using the
connection string you are trying to use because only ADO.Net understands the
Userinstance parameter. You can definitely attach it to SQL Express and
access it the way you would any other database. You can also access it
through the named pipe name but that's not something I would recommend for a
production system. More information on user instances is available here:
http://msdn2.microsoft.com/en-us/library/bb264564.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Bart" <b@.sdq.dc> wrote in message
news:%23kiVRyZbHHA.4832@.TK2MSFTNGP02.phx.gbl...
> Thanks, so the conclusion is:
> it's impossible to access a MDF file with classic asp?
> "Roger Wolter[MSFT]" <rwolter@.online.microsoft.com> schreef in bericht
> news:EF1406A3-C657-44F9-8FF6-3F1D032175E1@.microsoft.com...
>|||"You can definitely attach it to SQL Express and
access it the way you would any other database."
Do you mean: starting sql server management studio and there attaching the
MDF file?
But then i loose the benefit of having a MDF file which can be
administratted independantly of sql server ...
About named pipe name, i installed sqlexpress as "default" (not named
instance).
"Roger Wolter[MSFT]" <rwolter@.online.microsoft.com> schreef in bericht
news:O16huWabHHA.596@.TK2MSFTNGP06.phx.gbl...
> Depends on how you define impossible. You can't access it using the
> connection string you are trying to use because only ADO.Net understands
> the Userinstance parameter. You can definitely attach it to SQL Express
> and access it the way you would any other database. You can also access
> it through the named pipe name but that's not something I would recommend
> for a production system. More information on user instances is available
> here:
> http://msdn2.microsoft.com/en-us/library/bb264564.aspx
> --
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> "Bart" <b@.sdq.dc> wrote in message
> news:%23kiVRyZbHHA.4832@.TK2MSFTNGP02.phx.gbl...
>

How to Connect to a SQL server on a deferent machine using ASP.Net?

Hi,

I am trying to connect to a SQL server on a deferent machine using ASP.Net written in C#. The machine on which the SQL server reside dose not have the ASPNET user and the authentication is falling. Any ideas on how to connect using a different User. I changed the ASP.Net service on my machine to run as a deferent user MyUser, which is a domain user that have access to the server machine?

Note: We can not change the privileges on the server side.

Thanks.

RH

Hi,

I am looking to run a web service as a deferent user; it is running, as ASPNET and I would like it to run as a domain user. I am not sure if this is a configuration issue in the Dev studio. Please help.

Thanks.

Rafat

|||

You should post on an ASP.Net forum for instructions on how to set a specific login to be used by your application for connecting to SQL Server.

If you have questions about how to setup such a login in SQL Server, let us know.

Thanks
Laurentiu

|||

Please don't open different threads on the same topic.

Thanks
Laurentiu

Friday, March 23, 2012

how to connect to .mdf file with sqmcmd?

Hi,
i have several mdf files for several asp.net applications. How can i reach
such a database with sqlcmd?
Thanks
BobThe .mdf is just the data file it is not the server. Have you looked up
sqlcmd in BooksOnLine?
Andrew J. Kelly SQL MVP
"Bob" <bob@.omail.nl> wrote in message
news:OuGOrItVHHA.496@.TK2MSFTNGP06.phx.gbl...
> Hi,
> i have several mdf files for several asp.net applications. How can i reach
> such a database with sqlcmd?
> Thanks
> Bob
>|||Take a look into the below URL:-
http://msdn2.microsoft.com/en-us/library/ms162773.aspx
Thanks
Hari
"Bob" <bob@.omail.nl> wrote in message
news:OuGOrItVHHA.496@.TK2MSFTNGP06.phx.gbl...
> Hi,
> i have several mdf files for several asp.net applications. How can i reach
> such a database with sqlcmd?
> Thanks
> Bob
>|||Thanks, i know that mdf is not the server. All i ask is: is it possible to
manage such a database with sqlcmd (something like 'use mymdf_file'). Maybe
that file is attached to the server ...
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> schreef in bericht
news:%233v%23A1uVHHA.1036@.TK2MSFTNGP03.phx.gbl...
> The .mdf is just the data file it is not the server. Have you looked up
> sqlcmd in BooksOnLine?
> --
> Andrew J. Kelly SQL MVP
> "Bob" <bob@.omail.nl> wrote in message
> news:OuGOrItVHHA.496@.TK2MSFTNGP06.phx.gbl...
>|||Not that I know of. Ssqlcmd talks to the server instance not the file. You
can specify a db name in the connection string but not a file.
Andrew J. Kelly SQL MVP
"Ken" <kns@.shdv.sd> wrote in message
news:%23M3$h8yVHHA.4404@.TK2MSFTNGP03.phx.gbl...
> Thanks, i know that mdf is not the server. All i ask is: is it possible to
> manage such a database with sqlcmd (something like 'use mymdf_file').
> Maybe that file is attached to the server ...
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> schreef in bericht
> news:%233v%23A1uVHHA.1036@.TK2MSFTNGP03.phx.gbl...
>

How to Connect SQL server Using ASP.net

Dear ASP.NET user...

I'm a new user in ASP.NET...
i have a problem facing now...
I'm using SQL server as my database...
how do i CONNECT my web application using ASP.NET to SQL server??

What should i do?
any coding do i need to insert to my web HTML?

what i heard from my friend...she said web config can connect the web application to SQL server...?...it that work?

pls help me guys and gals...

From jhwong2610
URGENTVery often the web.config is used to store the connection string - that alone does not connect you to a database - using the connection string you have to open a sqlConnection and then proceed from there.

My best recommendation would be to pick up one of the ASP.NET books and look at one of the examples that uses data binding.|||Hi:
Like This


Dim Conn As New SqlConnection("ConnectionStringHere")
Dim Conn As New SqlCommand("Select * From Table", Conn)
Dim DRs As SqlDataReader
Conn.Open()
DRs = Comm.ExecuteReader()
If DRs.Read() Then
Response.Write(DRs("Column"))
End If
DRs.Close()
Conn.Close()
|||Add this to the web.config file:

<configuration>
<appSettings>
<add key="SQLConnStr" value="<your connection string" />
</appSettings
...

You can use the connectionstring in the code like this:

Dim str as connStr = System.Configuration.ConfigurationSettings.AppSettings("SQLConnStr")

Wednesday, March 21, 2012

how to connect from asp

How do I connect to sql server express from asp.

to sql server I would do as follows but this is not working with sql server express

<%
Dim objconn ,mserver,dbName,UserID_db, PassWD
Dim strCon
Set objconn=Server.CreateObject("ADODB.Connection")
mserver="iphere"
dbName="dbname"
UserID_db="login"
PassWD="password"
strCon="Provider=SQLOLEDB.1;Data Source=" & mServer & ";Initial Catalog=" & _
dbName & ";User ID=" & UserID_db & ";Password=" & PassWD & ";"
objconn.Open strCon
response.write "opened"


%

Did you enabled remote connections for SQl Server Express (this is disabled by default). See the screeencast on my site for more information. SQL Server grabs a dynamically assigned port at startup, so you either specify the port after the servername --> Servername,Portnumber or start SQL Server browser on the server which will redirect the request to the appropiate port.

HTH, Jens K. Suessmeyer.

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

Hi,

Also check if NET DDE and NET DDE DSDM services are started under Administrative Tools->Services

and Firewall rules are set properly to allow connection.

Hemantgiri S. Goswami

how to connect data base in sql

Hi
I have a problem with my data base.
when i run my project (ASP.NET) in Vs 2005 my data base work.
but i run in localhost isn′t work.
my data base as a .mdf(sql server)
Can help-me ?
Are you getting an error or isnt simply not working? Do you meanwhen you run it under IIS [as oppose to the development server] itdoesnt work?
|||yes it is an error message and it happens when i'm runing the IIS
The Link of my server is http://ocodigo.no-ip.info
Open a "Registar" option, you full fill then spaces and press "Registar" Botton, and next you will see the error.
|||Hello WATT
I couldn't see the error message. I think u have to change something inthe "web.config" file, so we could see the error message.
Because i got this message:

Server Error in '/' Application.

Runtime Error

Description:Anapplication error occurred on the server. The current custom errorsettings for this application prevent the details of the applicationerror from being viewed remotely (for security reasons). It could,however, be viewed by browsers running on the local server machine.
Details: To enable thedetails of this specific error message to be viewable on remotemachines, please create a <customErrors> tag within a"web.config" configuration file located in the root directory of thecurrent web application. This <customErrors> tag should then haveits "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>


Notes:The current error page you are seeing can be replaced by a custom errorpage by modifying the "defaultRedirect" attribute of the application's<customErrors> configuration tag to point to a custom error pageURL.

<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>


Mow

how to connect asp.net to sql server 2k

i have this error in my asp.net

>Server Error in '/' Application.
>------------------------
>SQL Server does not exist or access denied.
>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
>Exception Details: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
>Source Error:
>
>Line 23: Dim sText As String = "SELECT employeeid, firstname, lastname FROM Employees"
>Line 24: Dim cmd As SqlDataAdapter= New SqlDataAdapter(sText, sConn)
>Line 25: cmd.Fill(ds, "EmpTable")
>Line 26:
>Line 27: Session("MyData") = ds
>
>Source File: c:\inetpub\wwwroot\FormViewer.aspx Line: 25

and my connection string is :

>"server=localhost;uid=sa;Initial Catalog=Northwind;"

i tried a lot of codes but it doesn't work in sql server 2k but in mysql server it perfectly run. i installed my web server in my local machine with .net framework but my sql server 2k is installed in other machine with the domain controller setup. how im going to connect to my sql server 2k using asp.net codes. i learn some ideas that it better to code the connection string in web.config. is it ok? please please help me. im really out of mind.hi everybody, im a newbie in asp.net. my current language is vb/sqlserver2k. i have a problem in connecting asp.net to sql server2k because my sql server2k is installed in other machine and my web server is installed in my local machine together with my .net framework. i tried a lot of examples but none of this is working with application, it shows with an error "SQL Server does not exist or access denied."
can you give me a complete source step by step. i would really appreciate if anybody can help. thanks in advance|||Tryhttp://www.connectionstrings.com for connection string help. If you still can't get it working, is your SQL Server using SQL authentication or Windows authentication? What does your connection string look like (be sure not to post actual user names and passwords if you are using SQL authentication)?

Edit: I found your duplicate post on the same topic and joined it to this thread. Please do not post the same question multiple times. It only frustrates those who are trying to help you and dilutes the effort.|||how can i know what authentication am i using, sql authentication or windows authentication?
all i know that in my vb application i was using this connection string to connect to my sql server "provider=sqloledb;database=xxxx;server=xxxx;uid=xxx;pwd=xxxx" is that so simple in my vb but in asp.net i really don't know what is the correct connection. thanks anyway tmorton for your reply|||Use the connection string example under SQL Server, SqlConnection, Standard Security at connectionstrings.com.

You are using SQL authentication since you are using a user name and password to connect. If you were using Windows authentication there would be no user name or password; the credentials of the current user would be used.

How to connect 2 table in one database.

Hi everyone.

Please Help Me.

Asp.net using C#.Net and Backend Sql server 2005.

1. How to conection 2 table at the same time.in c#.net.

2.How to Insert,update and delete for 1 or 2 table connections.

all the code give C#.Net in asp.net.

Thanks.

Hi, don't quite get your questions. What are you trying to do? What do you mean by connect 2 tables at the same time? Once you open a connection, you can access as many tables as you want through the connection; if the two tables are in two different database, you can open one connection for each database and then access yor tables.

Same confusion with the question 2. Don't know what you are asking.

Sorry

|||You should do some research on the SQL Join clause. Here's a starter for you: http://www.google.com/search?hl=en&q=sql+join&btnG=Google+Search&meta=|||

single database. 2 table at a time insert a values.

for example :

viswa is database.

student is a one table.

college fees is a one table.

student id is uni key

at a time 2 table insert a values.

please giveinsert, update and delete in c#.Net

|||

Those tables are not related. There is no reason that you should be performing operations on both tables at the same time. Nothing in college fees should relate to anything in student. If it does, then you need to look at your database design.

Also, C# does not offer any INSERT, UPDATE or DELETE procedures. You use the SQL language to perform operations against a database. You then use C# (or VB.Net, or J# etc) to get ADO.NET to present SQL commands to the database.


|||

I have Only one database and mutiple table.

database name = employee

table name = employee details

table name = employee salary

table name = department

morte...

I connect a database . how to select 2 tables.

my question isbatch process (multiple insert, update and delete ) in 2 tables

Sunday, February 19, 2012

How to check/verify SQL login Credential

Hi,

I am making a module to backup SQL Db from webpage. I impersonate asp.net user to a given Windows Account and need to verify that account has required permission in SQL Server.

I don't know how to verify the windows account credential for SQL Server login.

Now what I am doing is to run SQL query against database to select row from some table, if it is successful, the user is valid SQL login. But I know it's not the way.

Any idea?

Thanks,

Why don't you just try to login and do the backup and if it fails you know you don't have permission

how to check whether sql statement is executed

Hi,
I have a few sql statements in asp. How do I check that the first sql statement is executed before the second one? If the first sql statement does not execute, then the second one will not execute too.Varierty of ways...
What queries are we talking about... can you post them? Are we talking SELECTs or UPDATE/DELETEs ?|||Originally posted by autumn6
Hi,

I have a few sql statements in asp. How do I check that the first sql statement is executed before the second one? If the first sql statement does not execute, then the second one will not execute too.

May be @.@.ROWCOUNT (Returns the number of rows affected by the last statement) will help you to find decision. You can get value from ADO.|||how about a stored procedure that has all the statements with an IF after the first one?|||Originally posted by LFN
Varierty of ways...
What queries are we talking about... can you post them? Are we talking SELECTs or UPDATE/DELETEs ?

It's a few INSERT statements.|||Its my understading that an INSERT operation will either succeed - or fail with an error (not necessarily a fatal error though)

So if its just INSERTS youre doing then check for a non-fatal error. Obviously a fatal error will abort your code anyway.

You might want to consider using a transaction... just to make sure they all go - or none as required...

Then after each INSERT do the error check...

IF (@.@.ERROR <> 0) ... [ take action - maybe a goto error routine ].....

That will catch any non-fatal errors - if there wasnt one the INSERT worked.

LFN