Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting MatchError even when passing correct credential #116

Open
nitesh-christies opened this issue Nov 23, 2020 · 10 comments
Open

Getting MatchError even when passing correct credential #116

nitesh-christies opened this issue Nov 23, 2020 · 10 comments

Comments

@nitesh-christies
Copy link

State: Tds.Protocol
[error] GenServer #PID<0.601.0> terminating
** (RuntimeError) connect raised MatchError exception. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
(tds) lib/tds/tokens.ex:362: Tds.Tokens.decode_envchange/2
(tds) lib/tds/tokens.ex:52: Tds.Tokens.decode_tokens/2
(tds) lib/tds/messages.ex:66: Tds.Messages.parse/3
(tds) lib/tds/protocol.ex:507: Tds.Protocol.decode/2
(tds) lib/tds/protocol.ex:562: Tds.Protocol.login/1
(tds) lib/tds/protocol.ex:408: Tds.Protocol.connect/2
(db_connection) lib/db_connection/connection.ex:69: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil

@nitesh-christies
Copy link
Author

State: Tds.Protocol
[error] GenServer #PID<0.625.0> terminating
** (MatchError) no match of right hand side value: <<10, 68, 0, 82, 0, 65, 0, 90, 0, 79, 0, 66, 0, 73, 0, 83, 0, 81, 0, 76, 0, 0, 173, 54, 0, 1, 116, 0, 0, 4, 22, 77, 0, 105, 0, 99, 0, 114, 0, 111, 0, 115, 0, 111, 0, 102, 0, 116, 0, 32, ...>>
(tds) lib/tds/tokens.ex:362: Tds.Tokens.decode_envchange/2
(tds) lib/tds/tokens.ex:52: Tds.Tokens.decode_tokens/2
(tds) lib/tds/messages.ex:66: Tds.Messages.parse/3
(tds) lib/tds/protocol.ex:507: Tds.Protocol.decode/2
(tds) lib/tds/protocol.ex:562: Tds.Protocol.login/1
(tds) lib/tds/protocol.ex:408: Tds.Protocol.connect/2
(db_connection) lib/db_connection/connection.ex:69: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil

@mjaric
Copy link
Member

mjaric commented Nov 23, 2020

I can't test this since I don't have env with mirroring, but from binary you posted in second comment it stuck on eventchange message for mirroring partner. This line. It must be removed for tail, and return it for further processing since transaction and other useful stuff is also there and we need to read it. But I'm confused why it isn't work for you, here is what code does:

before_match_tail = <<10,     68, 0, 82, 0, 65, 0, 90, 0, 79, 0, 66, 0, 73, 0, 83, 0, 81, 0, 76, 0     , 0 .... >>
<<
10, # <--- new_value_size unsigned 1 byte integer, in this case it tells that we have to read 10 ucs2 chars ahead
68, 0, 82, 0, 65, 0, 90, 0, 79, 0, 66, 0, 73, 0, 83, 0, 81, 0, 76, 0, # <--- _new_value is matched as binary-size(10)-unit(16) ucs2 string
0, # <--- as expected one byte set to 0x00
rest # <--- the rest of the binary or nil if it is at the end
>>

so this should work, right?

tail = <<10, 68, 0, 82, 0, 65, 0, 90, 0, 79, 0, 66, 0, 73, 0, 83, 0, 81, 0, 76, 0, 0, 173, 54, 0, 1, 116, 0, 0, 4, 22, 77, 0, 105, 0, 99, 0, 114, 0, 111, 0, 115, 0, 111, 0, 102, 0, 116, 0, 32>>
# there is more bytes in your message "...", but this should enough to prove above

<<len::unsigned-8, server_name::binary-size(len)-unit(16), 0x00, rest::binary>> = tail
server_name = server_name
  |> String.to_charlist()
  |> Enum.reject(&(&1 == 0))
  |> IO.iodata_to_binary()
  |> IO.inspect(label: "ServerName")

Above should print your server name

Just one thing, what is your erlang, elixir and TDS version?

@nitesh-christies
Copy link
Author

erlang OTP: 21
elixir: 1.8.1 and also tried with 1.10.4

tdsL 2.1

@mjaric
Copy link
Member

mjaric commented Nov 23, 2020

Could you try last code snippet on your computer?, no deps is required, it can be run in iex too

@nitesh-christies
Copy link
Author

Hi Mjaric

Haven't tried yet.. Let me try and tell you

Also, I am really sorry I can not share env

@nitesh-christies
Copy link
Author

nitesh-christies commented Nov 23, 2020

Hey I am getting the server name DRAZOBISQL

@mjaric
Copy link
Member

mjaric commented Nov 23, 2020

You don't have to share env, don't worry. We can fix this here too.

Next thing that could be an issue is Tds.BinaryUtils.binary/2 macro. What I'd like you to do is to checkout :tds master locally and plug it to your app in mix deps e.g. {:tds, path: "../../some/path/to/tds_master"}. Then head to this file and line and replace:

_new_value::binary(new_value_size, 16), with _new_value::binary-size(new_value_size)-unit(16),

This should remove usage of binary/2 macro.

Let me know if app can login then on the same server? thanks

@mjaric
Copy link
Member

mjaric commented Dec 3, 2020

@nitesh-christies Any luck?

@nitesh-christies
Copy link
Author

Hi @mjaric

@nitesh-christies
Copy link
Author

Thank you for asking.... Still, no luck tried all this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants