Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Wednesday, March 28, 2012

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 ssis service - The RPC server is unavailable err

Hi
I am trying to connect to ssis service on remote machine using the sql 2005
management studio
I get the following error :
TITLE: Connect to Server
Cannot connect to <servername>.
Connect to SSIS Service on machine "<servername>" failed:
The RPC server is unavailable.
What do I miss please help
Best regards
Meron Fridman
Did you figure out a solution ? I have the same problem.
homebrew
homebrew's Profile: http://www.dbtalk.net/m55
View this thread: http://www.dbtalk.net/t290084

how to connect to ssis service - The RPC server is unavailable err

Hi
I am trying to connect to ssis service on remote machine using the sql 2005
management studio
I get the following error :
TITLE: Connect to Server
Cannot connect to <servername>.
Connect to SSIS Service on machine "<servername>" failed:
The RPC server is unavailable.
What do I miss please help
Best regards
Meron FridmanDid you figure out a solution ' I have the same problem.
homebrew
---
homebrew's Profile: http://www.dbtalk.net/m55
View this thread: http://www.dbtalk.net/t290084|||I found out that one of our developers (developer #1) wasn't having any
problems, and that he had used a different disk to install on his
desktop. So then developer #2 used his disk, and her problem went away.
I had already put in a call to Microsoft, and we tested my RPC ports
and they seemed fine. So I think I got a bad disk ... perhaps some
file is corrupted ?
Then he had another utility for me to try, but I haven't bothered yet,
since I'm pretty sure it's the disk, and not something on my desktop.
homebrew
---
homebrew's Profile: http://www.dbtalk.net/m55
View this thread: http://www.dbtalk.net/t290084

How to connect to SQL Server with ASP.NET

Hi
I need help to connect to SQL server, i got Microsoft Visual Web Developer 2005 Express and SQL Server Management Studio Express
With SQL Server Management Studio Express i can make databases and create tables but i dunno how to connect via asp.net
Anyone could give me a helping hand?
Thanks for the help
- Gucchi

Hi
Following is the sample create_connection method that works for me.Hope this helps you.
ALL THE BEST
Chickoo
Sub create_Conn()

Dim oConnectionAs SqlConnection

Dim DAAs SqlDataAdapter

Dim DSAsNew DataSet

Dim sSQLAsString

Dim sConnAs SqlConnection =New SqlConnection("workstation id=<xxx>;packet size=4096;integrated security=SSPI;data source=<xxx >;persist security info=False;initial catalog=<Database Name>;Trusted_Connection=Yes")

sSQL = " SELECT * FROM MyDatabase"

DA =New SqlDataAdapter(sqlstr, sConn)

DA.Fill(DS, "MyTable")

MyGrid.DataSource = DS

MyGrid.DataBind()

sConn.Close()

EndSub

sql

Friday, March 23, 2012

How to connect Report in ReportViewer to a datasource?

Hi:

I am new to ReportViewer. I have an .aspx page that takes data that makes a request for a Permit. When the User clicks submit, I add the record to the database then get the unique identity of that record and display it in a popup (as a confirmation number). I would then like a report to show the data the User just submitted.

I have added an .aspx page called RequestReport.aspx and put a ReportViewer on it. I added a report called PermitRequest.rdlc with a textbox that acts as a Title. I linked RequestReport to pull PermitRequest.rdlc and it successfully displays the report. My question is that I don't know how to add a datasource to the report to show the new record. I did save the unique record id to a Session variable called "RequestID".

Please help with directions.

Thanks in advance!

a few questions:

1) Are you using textbox to display the report or some other contrl (like a table)

2) Do you want an SQL type solution that you can handle programatically or a solution where the report is tied to a fixed dataset.

3) What IDE are you using (Visual Web Express or Studio)

bullpit

|||

Hi:

(1) I am using a textbox to display the report name and a table to display the data.

(2) Either one is OK. I just want to be able to pass the newly given unique id to the report and then have the report display only the record data for that id. Each record will change with each user and each new entry.

(3) Visual Studio 2005 SP1 and framework 2.0 talking to a SQL Server 2000 database.

I now have the report displaying all records, but I only want to display the last saved record. Do I need to set a parameter to pass? If so, I see how to pass it programmatically with VB code behind. I don't see how I tell the report to accept a parameter as part of the SQL Statement.

|||

The way I do, I handle everything from codebehind...that gives me more control...that way i can send an SQL query to fetch whatever i want...in your case, you have the id...build a select query string in codebehind to select only the records with that id...then bind to the report...

these two funtions will help you get started if you want to go that way:

public void FindAll()
{
// Set the processing mode for the ReportViewer to Local
ReportViewer1.ProcessingMode = ProcessingMode.Local;
LocalReport rep = ReportViewer1.LocalReport;
rep.ReportPath = "Report.rdlc";
DataSet ds = GetSalesDataFull();
// Create a report data source for the sales order data
ReportDataSource dsMaintenanceDS = new ReportDataSource();
dsMaintenanceDS.Name = "DataSet1_Main";
dsMaintenanceDS.Value = ds.Tables["Main"];
rep.DataSources.Clear();

//example to set report parameter values from codebehind
ReportParameter param = new ReportParameter("nRows", dDownListNRows.SelectedValue);
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { param });


rep.DataSources.Add(dsMaintenanceDS);
rep.Refresh();
}

private DataSet GetSalesDataFull()
{
DataSet ds = new DataSet();
string str = "";

str = @." WHERE ""ID""='" + <YOUR ID> ')";
string sqlSalesData = @."SELECT * FROM <TABLE NAME> " + str;

OdbcConnection connection = new OdbcConnection(<CONNECTION STRING>);
OdbcCommand command = new OdbcCommand(sqlSalesData, connection);
OdbcDataAdapter salesOrderAdapter = new OdbcDataAdapter(command);
salesOrderAdapter.Fill(ds, "Main");
salesOrderAdapter.Dispose();
command.Dispose();
return ds;
}

let me know if you have more questions.

good luck...bullpit

|||

The way I do, I handle everything from codebehind...that gives me more control...that way i can send an SQL query to fetch whatever i want...in your case, you have the id...build a select query string in codebehind to select only the records with that id...then bind to the report...

these two funtions will help you get started if you want to go that way:

public void FindAll()
{
// Set the processing mode for the ReportViewer to Local
ReportViewer1.ProcessingMode = ProcessingMode.Local;
LocalReport rep = ReportViewer1.LocalReport;
rep.ReportPath = "Report.rdlc";
DataSet ds = GetSalesDataFull();
// Create a report data source for the sales order data
ReportDataSource dsMaintenanceDS = new ReportDataSource();
dsMaintenanceDS.Name = "DataSet1_Main";
dsMaintenanceDS.Value = ds.Tables["Main"];
rep.DataSources.Clear();

//example to set report parameter values from codebehind
ReportParameter param = new ReportParameter("nRows", dDownListNRows.SelectedValue);
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { param });


rep.DataSources.Add(dsMaintenanceDS);
rep.Refresh();
}

private DataSet GetSalesDataFull()
{
DataSet ds = new DataSet();
string str = "";

str = @." WHERE ""ID""='" + <YOUR ID> ')";
string sqlSalesData = @."SELECT * FROM <TABLE NAME> " + str;

OdbcConnection connection = new OdbcConnection(<CONNECTION STRING>);
OdbcCommand command = new OdbcCommand(sqlSalesData, connection);
OdbcDataAdapter salesOrderAdapter = new OdbcDataAdapter(command);
salesOrderAdapter.Fill(ds, "Main");
salesOrderAdapter.Dispose();
command.Dispose();
return ds;
}

let me know if you have more questions.

good luck...bullpit

|||

Hi Bullpit:

Thank you for your response. Do you have this in Visual Basic code behind? Also, if i do this all in the code behind...will I still have the fields in the dataset on the report to drag and drop to the table on the report? Will I still be able to layout the design of the report?

|||

Sorry, I do not have this code in VB. And yes, you will be able to design the table the way you want. I wanted my report to be dynamic, so I gave the user the choice to choose the fields she/he wants on the report..so whatever field name user chooses, corresponding values are bound to that column in details section...but if you don't want that, you can have the column names as static (by drag and drop)...i believe it should work...also, there are several tools online to convert c# to vb...you can use them...

P.S. If you choose to go codebehind, then remember to add the name of the datasource (in our case "DataSet1_Main") in the Report Data Source option in IDE.

good luck

Wednesday, March 21, 2012

How to connect instance on local server

hi!
I have a question about connecting instance on local server
I install MS SQL Server 2000 first
and then install MS SQL Server 2005.
2005 has an instance name called "2005"
I use Microsoft SQL Server Management Studio and log into 2000
I want to select data from 2005
so I write a script "SELECT * FROM [local\2005].TESTDB.dbo.TEST
but it fail..
I also try following name
[local$2005].TESTDB.dbo.TEST but also fail
How can I connect these two SQL Server?
Can anyone give me a advice?
Thanks a lot!
You can create a likned server between the two instances. register either
the 2000 in 2005 or the other way around. Once a linked server is created,
you can execute a query similar to this
SELECT something FROM [server\instance].db.schema.table
You can do a lot of things in here - create a network alias for an instance
name to make it simple if you don't want to use a server\instance name
calls, create a DNS entry that points to the instance name, etc.
"YesGoGoGo" <YesGoGoGo@.gmail.com> wrote in message
news:1185939323.853710.99990@.e16g2000pri.googlegro ups.com...
> hi!
> I have a question about connecting instance on local server
> I install MS SQL Server 2000 first
> and then install MS SQL Server 2005.
> 2005 has an instance name called "2005"
> I use Microsoft SQL Server Management Studio and log into 2000
> I want to select data from 2005
> so I write a script "SELECT * FROM [local\2005].TESTDB.dbo.TEST
> but it fail..
> I also try following name
> [local$2005].TESTDB.dbo.TEST but also fail
> How can I connect these two SQL Server?
> Can anyone give me a advice?
> Thanks a lot!
>

How to connect instance on local server

hi!
I have a question about connecting instance on local server
I install MS SQL Server 2000 first
and then install MS SQL Server 2005.
2005 has an instance name called "2005"
I use Microsoft SQL Server Management Studio and log into 2000
I want to select data from 2005
so I write a script "SELECT * FROM [local\2005].TESTDB.dbo.TEST
but it fail..
I also try following name
[local$2005].TESTDB.dbo.TEST but also fail
How can I connect these two SQL Server?
Can anyone give me a advice?
Thanks a lot!You can create a likned server between the two instances. register either
the 2000 in 2005 or the other way around. Once a linked server is created,
you can execute a query similar to this
SELECT something FROM [server\instance].db.schema.table
You can do a lot of things in here - create a network alias for an instance
name to make it simple if you don't want to use a server\instance name
calls, create a DNS entry that points to the instance name, etc.
"YesGoGoGo" <YesGoGoGo@.gmail.com> wrote in message
news:1185939323.853710.99990@.e16g2000pri.googlegroups.com...
> hi!
> I have a question about connecting instance on local server
> I install MS SQL Server 2000 first
> and then install MS SQL Server 2005.
> 2005 has an instance name called "2005"
> I use Microsoft SQL Server Management Studio and log into 2000
> I want to select data from 2005
> so I write a script "SELECT * FROM [local\2005].TESTDB.dbo.TEST
> but it fail..
> I also try following name
> [local$2005].TESTDB.dbo.TEST but also fail
> How can I connect these two SQL Server?
> Can anyone give me a advice?
> Thanks a lot!
>sql

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

Monday, March 12, 2012

How to configure MSDE to listen on TCP/IP

Hi:
I'm not able to connect to MSDE remotely. From the SQL Server logs, it
is listening on Shared Memory only. How do I configure it to listen on
TCP/IP ?
The MSDE is running on WinXP Pro SP2, and there is a instance of
SQL2005 Express installed side by side, the SQL2005 Express is
configure to listen on port 1618. The firewall already turned off.
Another problem is related to SQL2005 Express... I'm not able to
connect to the SQL2005 Express remotely when the firewall turned ON,
even port 1618 is already add into exception list.
Any idea ?
Thanks
JCVoonProblem solved. I enable the Named Pipes protocol using SVRNETCN.exe
and restart the MSDE.
Why must enabled the Named Pipes when I only need TCP/IP protocol '
JCVoon
On Jan 25, 12:45 pm, "jcvoon" <jiangchnan.v...@.maximas.com> wrote:
> Hi:
> I'm not able to connect to MSDE remotely. From the SQL Server logs, it
> is listening on Shared Memory only. How do I configure it to listen on
> TCP/IP ?
> The MSDE is running on WinXP Pro SP2, and there is a instance of
> SQL2005 Express installed side by side, the SQL2005 Express is
> configure to listen on port 1618. The firewall already turned off.
> Another problem is related to SQL2005 Express... I'm not able to
> connect to the SQL2005 Express remotely when the firewall turned ON,
> even port 1618 is already add into exception list.
> Any idea ?
> Thanks
> JCVoon|||network communications are typically more interactive for named pipes wherea
s.
data transmissions are more streamlined and have less overhead in TCP/IP
You can have more in SQL BOL
"jcvoon" wrote:

> Problem solved. I enable the Named Pipes protocol using SVRNETCN.exe
> and restart the MSDE.
> Why must enabled the Named Pipes when I only need TCP/IP protocol '
> JCVoon
>
> On Jan 25, 12:45 pm, "jcvoon" <jiangchnan.v...@.maximas.com> wrote:
>|||> Another problem is related to SQL2005 Express... I'm not able to
> connect to the SQL2005 Express remotely when the firewall turned ON,
> even port 1618 is already add into exception list.
You have to add the C:\Program Files\Microsoft SQL
Server\90\Shared\sqlbrowser.exe into the exceptions list.