Tuesday, March 20, 2012
Connection Open Exemptions
Using VB .NET is there a way to return/track the reason why a connection has
failed to open. I want to be able to track the following reasons for
failure:
1. User doesn't have the correct permissions set to open the database
2. Unable to open the connection because the user setting are wrong, (server
name, username, password)
3. Using the wrong authentication - NT authentication instead of SQL Server
authentication and vis versa
Many thanks
Hello 11Oppidan,
Is this a duplicated post of "Security and Logins with ADO.NET"? If so,
please check my answer there and if you need any further assistance on this
particular issue, please reply to me in that thread so I can follow up with
you in time. Also, please don't post the same question in newsgroups in the
future so that our engineers can work on your question efficiently. Your
understanding and cooperation is appreciated.
If you'd like to troubleshoot the problem from the client computer, I
recommend you perform the following steps:
1. Install SQL client tools on the client computer. Check if the user can
log into SQL server using SQL Query Analyzer (QA). Check if the user can
run the SQL statement successfully.
If the user can log into SQL server using QA, it indicates that the user
has permissions on this SQL server.
Note: The user account can be either Windows account or SQL account.
After log into SQL server in QA, if the user can run the SQL statement
successfully, it indicates that the user has the correct permissions on the
database.
If the user cannot log into SQL server using QA, please try to log into QA
as sa or an administrative user. If the issue still exists, you can refer
to the following article:
How to troubleshoot connectivity issues in SQL Server 2000 (827422)
http://support.microsoft.com/default...B;EN-US;827422
2. Contact Product Support Services (PSS) to get mdactrace tool
If you want more detailed information about ADO connection, I recommend
that you open a Support incident with Microsoft Product Support Services
(PSS) so that a dedicated Support Professional can work with you in a more
timely and efficient manner. If you need any help in this regard, please
let me know.
For a complete list of Microsoft Product Support Services phone numbers,
please go to the following address on the World Wide Web:
<http://support.microsoft.com/directory/overview.asp>
If you are outside the US please see http://support.microsoft.com for
regional support phone numbers.
3. The output file of "sqldiag Utility".
Please execute the following command at the DOS prompt:
"C:\Program Files\Microsoft SQL Server\MSSQL\Binn\sqldiag.exe"
SQLdiag.exe is a command line utility that puts all the SQL server error
logs and other configuration settings into a text file.
Note:
a. Above command use the default folder. You may need to replace the right
folder which sqldiag.exe locates.
b. The generated log file SQLdiag.txt is located in Log folder.
Check the output file.
4. Windows application log
The following information is for your reference:
Viewing the Windows Application Log
<http://msdn.microsoft.com/library/de...-us/adminsql/a
d_perfmon_5qnn.asp>
Check the Windows Application Log file.
You may send me all output files for research at v-sguo@.Microsoft.com
I hope above information is helpful.
Sophie Guo
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/tec...rview/40010469
Others: https://partner.microsoft.com/US/tec...pportoverview/
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/default...national.aspx.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
|||Hi Sophie,
Thank you again for your time and respnse to my previous question regarding
the security settings. We solved that user problem thanks to your previous
answer. The problem was the user did not have read access to the master db
and we were querying this to return a list of db names attached to the
server. The dba gave her read permission to the master db and that resolved
the problem.
As a consequence of that problem I have realised that I need to change the
code I use to return a list of dbs names for the user to select, and that
was why I asked this second question.
Maybe this is not the best way to do it - but currently I query the master
db to return a list of attached db names. I then go through these opening
each db to check a certain tbl exists. If it does I know is one of the dbs
the user protentially needs to query and I add the name to a combobox item.
This seems to work fine if the user has the correct permissions and user
settings.
Unfortunately though dbas are not too generous with permissions, and
different companies operate very different security policies! So I want to
be able to establish the reason why a connection fails to open when called
in code (VB .NET), and use a try & catch to trap the reason why this is
happening so I can report it back to the user so they can take the right
action to resolve it. The three reasons I can think of why a connection
might fail to open were.
1. User doesn't have the correct permissions set to access the database
2. Unable to open the connection because the user has incorrectly entered
their settings (server
name, username, password)
3. The user has selected to use the wrong authentication - NT authentication
instead of SQL Server
authentication and vis versa.
So far I can only find how to return the state of the connection e.g.
cnn.State <>ConnectionState.Open then Exit Function
But it would be good if I could also trap an SqlException which indicated
which of these different reasons caused the open call to fail!
Your advice and feedback is much appreciated.
"Sophie Guo [MSFT]" <v-sguo@.online.microsoft.com> wrote in message
news:v8sanEoCFHA.2504@.cpmsftngxa10.phx.gbl...
> Hello 11Oppidan,
> Is this a duplicated post of "Security and Logins with ADO.NET"? If so,
> please check my answer there and if you need any further assistance on
> this
> particular issue, please reply to me in that thread so I can follow up
> with
> you in time. Also, please don't post the same question in newsgroups in
> the
> future so that our engineers can work on your question efficiently. Your
> understanding and cooperation is appreciated.
> If you'd like to troubleshoot the problem from the client computer, I
> recommend you perform the following steps:
> 1. Install SQL client tools on the client computer. Check if the user can
> log into SQL server using SQL Query Analyzer (QA). Check if the user can
> run the SQL statement successfully.
> If the user can log into SQL server using QA, it indicates that the user
> has permissions on this SQL server.
> Note: The user account can be either Windows account or SQL account.
> After log into SQL server in QA, if the user can run the SQL statement
> successfully, it indicates that the user has the correct permissions on
> the
> database.
> If the user cannot log into SQL server using QA, please try to log into QA
> as sa or an administrative user. If the issue still exists, you can refer
> to the following article:
> How to troubleshoot connectivity issues in SQL Server 2000 (827422)
> http://support.microsoft.com/default...B;EN-US;827422
>
> 2. Contact Product Support Services (PSS) to get mdactrace tool
> If you want more detailed information about ADO connection, I recommend
> that you open a Support incident with Microsoft Product Support Services
> (PSS) so that a dedicated Support Professional can work with you in a more
> timely and efficient manner. If you need any help in this regard, please
> let me know.
> For a complete list of Microsoft Product Support Services phone numbers,
> please go to the following address on the World Wide Web:
> <http://support.microsoft.com/directory/overview.asp>
> If you are outside the US please see http://support.microsoft.com for
> regional support phone numbers.
>
> 3. The output file of "sqldiag Utility".
> Please execute the following command at the DOS prompt:
> "C:\Program Files\Microsoft SQL Server\MSSQL\Binn\sqldiag.exe"
> SQLdiag.exe is a command line utility that puts all the SQL server error
> logs and other configuration settings into a text file.
> Note:
> a. Above command use the default folder. You may need to replace the right
> folder which sqldiag.exe locates.
> b. The generated log file SQLdiag.txt is located in Log folder.
>
> Check the output file.
>
> 4. Windows application log
> The following information is for your reference:
> Viewing the Windows Application Log
> <http://msdn.microsoft.com/library/de...-us/adminsql/a
> d_perfmon_5qnn.asp>
> Check the Windows Application Log file.
> You may send me all output files for research at v-sguo@.Microsoft.com
> I hope above information is helpful.
>
> Sophie Guo
> Microsoft Online Partner Support
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
> Business-Critical Phone Support (BCPS) provides you with technical phone
> support at no charge during critical LAN outages or "business down"
> situations. This benefit is available 24 hours a day, 7 days a week to all
> Microsoft technology partners in the United States and Canada.
>
> This and other support options are available here:
> BCPS:
> https://partner.microsoft.com/US/tec...rview/40010469
> Others: https://partner.microsoft.com/US/tec...pportoverview/
>
> If you are outside the United States, please visit our International
> Support page:
> http://support.microsoft.com/default...national.aspx.
> ================================================== ===
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>
|||Hi 11Oppidan,
As for getting the error info when fail to establish a sqlconnection, I
think the Exception throwed by the runtime
has containded some useful infos. For example:
When we create a new SqlConnection with invalid connectionstring such as
SqlConnection conn = new SqlConnection("#$#@.4234#@.$#@.$");
We'll Receive a "System.ArgumentException" indicate that we've provided
incorrect paratmeters
If the connstring is valid on syntax, then when we call Connection.Open,
the runtime will also throw SqlException with the proper exception message
according to the actual error. For example:
if we use a incorrect login user(username and password), it will return a
SqlException and its
"Message" property will contain
"Login failed for user 'XXXX'."
Also, if we input the wrong server name, the error Message may be something
like:
"SqlServer dosn't exist or access denied."
So generally, the normal way is to add try...catch block around our sql
code and read the Exception.Message property to get the error general error
info.
BTW, as for the 3rd reason you mentioned:
===================
3. The user has selected to use the wrong authentication - NT
authentication
instead of SQL Server
authentication and vis versa.
============================
I'm afraid the runtime (also sqlserver) may not support such checking. The
database will only valdating the comming request according to the request's
authentication type, but won't check whether it is using the wrong
authentication type or whether it may succeed through another type.
HTH. Thanks.
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Connection Open Exemptions
Using VB .NET is there a way to return/track the reason why a connection has
failed to open. I want to be able to track the following reasons for
failure:
1. User doesn't have the correct permissions set to open the database
2. Unable to open the connection because the user setting are wrong, (server
name, username, password)
3. Using the wrong authentication - NT authentication instead of SQL Server
authentication and vis versa
Many thanksHello 11Oppidan,
Is this a duplicated post of "Security and Logins with ADO.NET"? If so,
please check my answer there and if you need any further assistance on this
particular issue, please reply to me in that thread so I can follow up with
you in time. Also, please don't post the same question in newsgroups in the
future so that our engineers can work on your question efficiently. Your
understanding and cooperation is appreciated.
If you'd like to troubleshoot the problem from the client computer, I
recommend you perform the following steps:
1. Install SQL client tools on the client computer. Check if the user can
log into SQL server using SQL Query Analyzer (QA). Check if the user can
run the SQL statement successfully.
If the user can log into SQL server using QA, it indicates that the user
has permissions on this SQL server.
Note: The user account can be either Windows account or SQL account.
After log into SQL server in QA, if the user can run the SQL statement
successfully, it indicates that the user has the correct permissions on the
database.
If the user cannot log into SQL server using QA, please try to log into QA
as sa or an administrative user. If the issue still exists, you can refer
to the following article:
How to troubleshoot connectivity issues in SQL Server 2000 (827422)
http://support.microsoft.com/defaul...KB;EN-US;827422
2. Contact Product Support Services (PSS) to get mdactrace tool
If you want more detailed information about ADO connection, I recommend
that you open a Support incident with Microsoft Product Support Services
(PSS) so that a dedicated Support Professional can work with you in a more
timely and efficient manner. If you need any help in this regard, please
let me know.
For a complete list of Microsoft Product Support Services phone numbers,
please go to the following address on the World Wide Web:
<http://support.microsoft.com/directory/overview.asp>
If you are outside the US please see http://support.microsoft.com for
regional support phone numbers.
3. The output file of "sqldiag Utility".
Please execute the following command at the DOS prompt:
"C:\Program Files\Microsoft SQL Server\MSSQL\Binn\sqldiag.exe"
SQLdiag.exe is a command line utility that puts all the SQL server error
logs and other configuration settings into a text file.
Note:
a. Above command use the default folder. You may need to replace the right
folder which sqldiag.exe locates.
b. The generated log file SQLdiag.txt is located in Log folder.
Check the output file.
4. Windows application log
The following information is for your reference:
Viewing the Windows Application Log
<http://msdn.microsoft.com/library/d...n-us/adminsql/a
d_perfmon_5qnn.asp>
Check the Windows Application Log file.
You may send me all output files for research at v-sguo@.Microsoft.com
I hope above information is helpful.
Sophie Guo
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/te...erview/40010469
Others: https://partner.microsoft.com/US/te...upportoverview/
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/defaul...rnational.aspx.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi Sophie,
Thank you again for your time and respnse to my previous question regarding
the security settings. We solved that user problem thanks to your previous
answer. The problem was the user did not have read access to the master db
and we were querying this to return a list of db names attached to the
server. The dba gave her read permission to the master db and that resolved
the problem.
As a consequence of that problem I have realised that I need to change the
code I use to return a list of dbs names for the user to select, and that
was why I asked this second question.
Maybe this is not the best way to do it - but currently I query the master
db to return a list of attached db names. I then go through these opening
each db to check a certain tbl exists. If it does I know is one of the dbs
the user protentially needs to query and I add the name to a combobox item.
This seems to work fine if the user has the correct permissions and user
settings.
Unfortunately though dbas are not too generous with permissions, and
different companies operate very different security policies! So I want to
be able to establish the reason why a connection fails to open when called
in code (VB .NET), and use a try & catch to trap the reason why this is
happening so I can report it back to the user so they can take the right
action to resolve it. The three reasons I can think of why a connection
might fail to open were.
1. User doesn't have the correct permissions set to access the database
2. Unable to open the connection because the user has incorrectly entered
their settings (server
name, username, password)
3. The user has selected to use the wrong authentication - NT authentication
instead of SQL Server
authentication and vis versa.
So far I can only find how to return the state of the connection e.g.
cnn.State <>ConnectionState.Open then Exit Function
But it would be good if I could also trap an SqlException which indicated
which of these different reasons caused the open call to fail!
Your advice and feedback is much appreciated.
"Sophie Guo [MSFT]" <v-sguo@.online.microsoft.com> wrote in message
news:v8sanEoCFHA.2504@.cpmsftngxa10.phx.gbl...
> Hello 11Oppidan,
> Is this a duplicated post of "Security and Logins with ADO.NET"? If so,
> please check my answer there and if you need any further assistance on
> this
> particular issue, please reply to me in that thread so I can follow up
> with
> you in time. Also, please don't post the same question in newsgroups in
> the
> future so that our engineers can work on your question efficiently. Your
> understanding and cooperation is appreciated.
> If you'd like to troubleshoot the problem from the client computer, I
> recommend you perform the following steps:
> 1. Install SQL client tools on the client computer. Check if the user can
> log into SQL server using SQL Query Analyzer (QA). Check if the user can
> run the SQL statement successfully.
> If the user can log into SQL server using QA, it indicates that the user
> has permissions on this SQL server.
> Note: The user account can be either Windows account or SQL account.
> After log into SQL server in QA, if the user can run the SQL statement
> successfully, it indicates that the user has the correct permissions on
> the
> database.
> If the user cannot log into SQL server using QA, please try to log into QA
> as sa or an administrative user. If the issue still exists, you can refer
> to the following article:
> How to troubleshoot connectivity issues in SQL Server 2000 (827422)
> http://support.microsoft.com/defaul...KB;EN-US;827422
>
> 2. Contact Product Support Services (PSS) to get mdactrace tool
> If you want more detailed information about ADO connection, I recommend
> that you open a Support incident with Microsoft Product Support Services
> (PSS) so that a dedicated Support Professional can work with you in a more
> timely and efficient manner. If you need any help in this regard, please
> let me know.
> For a complete list of Microsoft Product Support Services phone numbers,
> please go to the following address on the World Wide Web:
> <http://support.microsoft.com/directory/overview.asp>
> If you are outside the US please see http://support.microsoft.com for
> regional support phone numbers.
>
> 3. The output file of "sqldiag Utility".
> Please execute the following command at the DOS prompt:
> "C:\Program Files\Microsoft SQL Server\MSSQL\Binn\sqldiag.exe"
> SQLdiag.exe is a command line utility that puts all the SQL server error
> logs and other configuration settings into a text file.
> Note:
> a. Above command use the default folder. You may need to replace the right
> folder which sqldiag.exe locates.
> b. The generated log file SQLdiag.txt is located in Log folder.
>
> Check the output file.
>
> 4. Windows application log
> The following information is for your reference:
> Viewing the Windows Application Log
> <[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/a[/ur
l]
> d_perfmon_5qnn.asp>
> Check the Windows Application Log file.
> You may send me all output files for research at v-sguo@.Microsoft.com
> I hope above information is helpful.
>
> Sophie Guo
> Microsoft Online Partner Support
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ========================================
=============
> Business-Critical Phone Support (BCPS) provides you with technical phone
> support at no charge during critical LAN outages or "business down"
> situations. This benefit is available 24 hours a day, 7 days a week to all
> Microsoft technology partners in the United States and Canada.
>
> This and other support options are available here:
> BCPS:
> https://partner.microsoft.com/US/te...erview/40010469
> Others: https://partner.microsoft.com/US/te...upportoverview/
>
> If you are outside the United States, please visit our International
> Support page:
> http://support.microsoft.com/defaul...rnational.aspx.
> ========================================
=============
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>|||Hi 11Oppidan,
As for getting the error info when fail to establish a sqlconnection, I
think the Exception throwed by the runtime
has containded some useful infos. For example:
When we create a new SqlConnection with invalid connectionstring such as
SqlConnection conn = new SqlConnection("#$#@.4234#@.$#@.$");
We'll Receive a "System.ArgumentException" indicate that we've provided
incorrect paratmeters
If the connstring is valid on syntax, then when we call Connection.Open,
the runtime will also throw SqlException with the proper exception message
according to the actual error. For example:
if we use a incorrect login user(username and password), it will return a
SqlException and its
"Message" property will contain
"Login failed for user 'XXXX'."
Also, if we input the wrong server name, the error Message may be something
like:
"SqlServer dosn't exist or access denied."
So generally, the normal way is to add try...catch block around our sql
code and read the Exception.Message property to get the error general error
info.
BTW, as for the 3rd reason you mentioned:
===================
3. The user has selected to use the wrong authentication - NT
authentication
instead of SQL Server
authentication and vis versa.
============================
I'm afraid the runtime (also sqlserver) may not support such checking. The
database will only valdating the comming request according to the request's
authentication type, but won't check whether it is using the wrong
authentication type or whether it may succeed through another type.
HTH. Thanks.
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
connection object to client ce
yo ce folks... Anyone had any trouble using a dataset for return values in a datagridview for the client app?
trying to make this work...
' Open the Connection For SQL Compact Edition
Dim cn As New SqlServerCe.SqlCeConnection("Data Source = " & Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\ffgsCRM.sdf")
Dim cmdProduct As SqlServerCe.SqlCeCommand
' create dataset with table
cn.Open()
cmdProduct = cn.CreateCommand
cmdProduct.CommandText = "SELECT ProductDesc AS Description, ProductCost AS Cost, ProductListPrice AS [List Price] FROM Product"
Dim daProduct As New SqlServerCe.SqlCeDataAdapter(cmdProduct)
Dim dtProduct As New Data.DataTable("Product")
daProduct.Fill(dtProduct)
Dim ds As New DataSet
ds.Tables.Add(dtProduct)
'' FILL DATAGRIDVIEW
Me.dbGridProducts.DataSource = ds
I have this working:
' search product description
Dim reqProductSearch As String
reqProductSearch = tstxtSearchDescription.Text
' Open the Connection For SQL Compact Edition
Dim _conn = New SqlCeConnection("Data Source = " & Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\ffgsCRM.sdf")
Dim cmd As New SqlCeCommand()
cmd.Connection = _conn
cmd.CommandText = "select ProductDesc as Description, ProductCost as Cost, ProductListPrice as [List Price] from Product where ProductDesc like '%" & reqProductSearch & "%' ORDER BY ProductDesc"
_conn.Open()
Dim resultSet As SqlCeResultSet
resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable Or ResultSetOptions.Updatable)
'' FILL DATAGRIDVIEW
dbGridProducts.DataSource = resultSet
With dbGridProducts
.Columns("Description").Width = 550
End With
Thanks,
Bill
Hi,did you try binding the table to the grid rather the dataset ? Did you get an error message on the first solution ? And why are you creating a dataset first just for binding ?
Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||
hi... on the first solution when i'm getting
(ArgumentException was unhandled) Child list for field ProductDesc cannot be created when i use either ProductDesc or just Description as it would be in a a regular dataset like in SQLExpress... etc...
Dim ds As New DataSet
ds.Tables.Add(dtProduct)
Me.dbGridProducts.DataSource = ds
Me.dbGridProducts.DataMember = "Description"
this fails... i need the dataset for grouping and such and would like to know how it's done with CE...
Thanks,
Bill
|||got my brain back... DataTable and Dataset examples... :)
'To Open the Connection To Connect to SQLCE
Dim ConsqlCombo As New SqlCeConnection
ConsqlCombo.ConnectionString = "Data Source = " & Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\ffgsCRM.sdf"
'SQL STATEMENT......
Dim reqSQLCombo As New SqlCeCommand
reqSQLCombo.CommandText = "select ProductDesc as Description, ProductCost as Cost, ProductListPrice as [List Price] from Product where ProductMfgID = '" & reqSearch & "'"
reqSQLCombo.CommandType = CommandType.Text
reqSQLCombo.Connection = ConsqlCombo
'CREATE NEW SQL DATA ADAPTER
Dim sqldaCombo As New SqlCeDataAdapter(reqSQLCombo)
Dim sqldsCombo As New DataSet
' FILL DATASET
sqldaCombo.Fill(sqldsCombo, "ProductDesc")
'' FILL DATAGRID
dbGridProducts.DataSource = sqldsCombo.Tables("ProductDesc")
dbGridProducts.DataMember = "ProductDesc"
connection object to client ce
yo ce folks... Anyone had any trouble using a dataset for return values in a datagridview for the client app?
trying to make this work...
' Open the Connection For SQL Compact Edition
Dim cn As New SqlServerCe.SqlCeConnection("Data Source = " & Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\ffgsCRM.sdf")
Dim cmdProduct As SqlServerCe.SqlCeCommand
' create dataset with table
cn.Open()
cmdProduct = cn.CreateCommand
cmdProduct.CommandText = "SELECT ProductDesc AS Description, ProductCost AS Cost, ProductListPrice AS [List Price] FROM Product"
Dim daProduct As New SqlServerCe.SqlCeDataAdapter(cmdProduct)
Dim dtProduct As New Data.DataTable("Product")
daProduct.Fill(dtProduct)
Dim ds As New DataSet
ds.Tables.Add(dtProduct)
'' FILL DATAGRIDVIEW
Me.dbGridProducts.DataSource = ds
I have this working:
' search product description
Dim reqProductSearch As String
reqProductSearch = tstxtSearchDescription.Text
' Open the Connection For SQL Compact Edition
Dim _conn = New SqlCeConnection("Data Source = " & Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\ffgsCRM.sdf")
Dim cmd As New SqlCeCommand()
cmd.Connection = _conn
cmd.CommandText = "select ProductDesc as Description, ProductCost as Cost, ProductListPrice as [List Price] from Product where ProductDesc like '%" & reqProductSearch & "%' ORDER BY ProductDesc"
_conn.Open()
Dim resultSet As SqlCeResultSet
resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable Or ResultSetOptions.Updatable)
'' FILL DATAGRIDVIEW
dbGridProducts.DataSource = resultSet
With dbGridProducts
.Columns("Description").Width = 550
End With
Thanks,
Bill
Hi,did you try binding the table to the grid rather the dataset ? Did you get an error message on the first solution ? And why are you creating a dataset first just for binding ?
Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||
hi... on the first solution when i'm getting
(ArgumentException was unhandled) Child list for field ProductDesc cannot be created when i use either ProductDesc or just Description as it would be in a a regular dataset like in SQLExpress... etc...
Dim ds As New DataSet
ds.Tables.Add(dtProduct)
Me.dbGridProducts.DataSource = ds
Me.dbGridProducts.DataMember = "Description"
this fails... i need the dataset for grouping and such and would like to know how it's done with CE...
Thanks,
Bill
|||got my brain back... DataTable and Dataset examples... :)
'To Open the Connection To Connect to SQLCE
Dim ConsqlCombo As New SqlCeConnection
ConsqlCombo.ConnectionString = "Data Source = " & Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\ffgsCRM.sdf"
'SQL STATEMENT......
Dim reqSQLCombo As New SqlCeCommand
reqSQLCombo.CommandText = "select ProductDesc as Description, ProductCost as Cost, ProductListPrice as [List Price] from Product where ProductMfgID = '" & reqSearch & "'"
reqSQLCombo.CommandType = CommandType.Text
reqSQLCombo.Connection = ConsqlCombo
'CREATE NEW SQL DATA ADAPTER
Dim sqldaCombo As New SqlCeDataAdapter(reqSQLCombo)
Dim sqldsCombo As New DataSet
' FILL DATASET
sqldaCombo.Fill(sqldsCombo, "ProductDesc")
'' FILL DATAGRID
dbGridProducts.DataSource = sqldsCombo.Tables("ProductDesc")
dbGridProducts.DataMember = "ProductDesc"
Monday, March 19, 2012
Connection Manager
I am using a connection manager defined as a '.Net Providers\SqlClient Data Provider'
I choose the .net form since it has the ability to return multiple result sets.
However, when I set the Advanced 'MultipleActiveResultsSets' to True and check OK,
it doesn't save the setting.
This setting is available under the 'All' window, when you add the Connection Manager.
Any clues as to why this feature isn't functional? Or is this a known bug?
I am piping this into a DataConversion Task
SSIS Data Flow adapters will work only with single result sets.
Thanks,
Bob
|||Thanks for the answer Bob.
I guess what SSIS appears to me to be is an updated DTS, some of the benefits are offset by the need to script advance functionality.
But isn't that what we did with DTS?
I just figured if you include .Net connections then you should support multiple result sets.
Is this a future option?
I am not completely disappointed with SSIS, but the learning curve doesn't appear to have that much of a reward when functionality like this is missing.
Again thanks for answering my question.
Thursday, March 8, 2012
Connection fails and currupt log
This has been working perfectly for over a year
Now various databases have started to return errors when queries are
run on the data from VB or Query Analyser.
A typical error is:
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
(CheckForData()).
Server: Msg 11, Level 16, State 1, Line 0
General Network Error. Check your network documentation
Connection broken
Not all the database produce errors but there appears to be no pattern
to which databases still work.
I have two backup copies of the main database they use. The main
database its self and one of the backups produce errors yet the other
backup, taken on the same day does not.
Looking at the error log (attached) there seems to be a lot of
"corrupt" entires.
Any suggestions* If you see corruption, then --
1. Check system and app event logs for details on any hardware corruption.
2. contact your hardware vendors to run some tests, diagnostics, etc and
also check for firmware upgrades.
3. Only then, RESTORE from your last healthy SQL Backup.
4. If you dont have a backup, then you could try to "Repair" the database
using "dbcc checkdb".
Thanks,
Vikram
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.
Friday, February 17, 2012
Connecting variable to database field
Greetings
what I need to do is access tables in a database, clean up one of the fields and return it to another table in the database. Im using a script component for the transformation whick looks for , or : and replaces : with a decimal point and removes the comma completely. My problem comes with the varaible-- how do I set this up so that the variable read matches the field in the database?
here is the script itself
thanks
km
Public Function AddList(list As String) As String
Dim total As Double
total = 0
If Len(list) > 0 Then
Dim s As Object
s = Split(list, ",")
Dim i As Integer
For i = LBound(s) To UBound(s)
s(i) = Replace(s(i), ":", ".")
total = total + CDbl(s(i))
Next
End If
AddList = total
End Function
km6589,
This would be better served in a stored procedure or function on the database side. That would solve your problem. Just run the SP in an Execute SQL Task.
If you don't care about overhead you could do this:
1) Drop a data flow task in the design.
2) Open the data flow task and add an OLE DB Source.
3) Open the OLE DB Source and add a connection if it isn't already there.
4) For the data access mode, choose SQL Command.
5) Add your SQL statement that lists the field you are trying to cleanup.
6) Add a Recordset Destination and feed the recordset into a variable of type object.
7) Access the variable for your recordset.
|||thanks
went ahead and wrote some sql to clean this up on the DB side
km
Connecting variable to database field
Greetings
what I need to do is access tables in a database, clean up one of the fields and return it to another table in the database. Im using a script component for the transformation whick looks for , or : and replaces : with a decimal point and removes the comma completely. My problem comes with the varaible-- how do I set this up so that the variable read matches the field in the database?
here is the script itself
thanks
km
Public Function AddList(list As String) As String
Dim total As Double
total = 0
If Len(list) > 0 Then
Dim s As Object
s = Split(list, ",")
Dim i As Integer
For i = LBound(s) To UBound(s)
s(i) = Replace(s(i), ":", ".")
total = total + CDbl(s(i))
Next
End If
AddList = total
End Function
km6589,
This would be better served in a stored procedure or function on the database side. That would solve your problem. Just run the SP in an Execute SQL Task.
If you don't care about overhead you could do this:
1) Drop a data flow task in the design.
2) Open the data flow task and add an OLE DB Source.
3) Open the OLE DB Source and add a connection if it isn't already there.
4) For the data access mode, choose SQL Command.
5) Add your SQL statement that lists the field you are trying to cleanup.
6) Add a Recordset Destination and feed the recordset into a variable of type object.
7) Access the variable for your recordset.
|||thanks
went ahead and wrote some sql to clean this up on the DB side
km
Friday, February 10, 2012
Connecting to SQL Server 2005 from Classic ASP
I am trying to return multiple recordsets to a classic ASP web page from SQL Server 2005 and then use GetRows() in ASP to fill 2 arrays with the data. I'm using a command object to run a stored procedure which performs 2 simple selects in SQL Server. The stored procedure works fine in SQL Server Management Studio so I'm guessing it's an ADO issue.
The ASP code looks like this:
strConnect = "DRIVER={SQL Native Client};SERVER=MyServer.IsAtMyIsp.com;DATABASE=MyDb;UID=Me;PWD=MyPwd; MARS Connection=True;"Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = strConnect
conn.Open
Set objCommand = Server.CreateObject("ADODB.Command")
Set objRecordset = Server.CreateObject("ADODB.Recordset")
Set objRs = Server.CreateObject("ADODB.Recordset")
With objCommand
.ActiveConnection = conn
.CommandText = "sp_GetShowList"
.CommandType = adCmdStoredProc
If Len(strBeginDate) And IsDate(strBeginDate) Then
.Parameters.Append .CreateParameter("@.i_DateStart",adDate,adParamInput,,strBeginDate)
If Len(strEndDate) And IsDate(strEndDate) Then
.Parameters.Append .CreateParameter("@.i_DateEnd",adDate,adParamInput,,strEndDate)
End If
End If
End With
Set objRs = objCommand.Execute
arrEvents = objRs.GetRows()
objRs.NextRecordset
arrSched = objRs.GetRows()
The error message below occurs at the 2nd GetRows() command.
Operation is not allowed when the object is closed.Can anyone tell me what I might be doing wrong?
-Dan
You don't assign the second recordset returned by NextRecordset to the recordset variable
Try
Set objRs = objCommand.Execute
arrEvents = objRs.GetRows()
objRs = objRs.NextRecordset
arrSched = objRs.GetRows()
That was so obvious I feel like an idiot. Thanks for the response!
-Dan